Ballance is a classic game where players use the keyboard to control a ball through complex structures high above the ground, avoiding falls while solving puzzles to reach the end of each level. Recently, the player community has developed online mods and hosts regular online competitions, such as the Grand Prix of Ballance.
The Grand Prix consists of $$$n$$$ levels, numbered from $$$1$$$ to $$$n$$$, with $$$m$$$ participants, numbered from $$$1$$$ to $$$m$$$. The competition uses a point system: players earn points based on their ranking in each level, and the sum of their points across all levels determines the final standings. Each level has a designated start time, and participants must complete the level as quickly as possible. As a staff member, you receive a server log during the match containing three types of messages (it is guaranteed that $$$1\le x\le n$$$ and $$$1\le id\le m$$$):
A Type 1 message indicates the start of Level $$$x$$$ until a new Type 1 message appears for a different level. Only messages that correspond to the currently active level are considered valid; all messages for other levels should be ignored. Messages before the first Type 1 message are also ignored. Each level appears at most once in a Type 1 message.
Each player may yield multiple Type 2 and Type 3 messages per level, but only the first valid message counts. Specifically:
Points are awarded to participants who complete the level as follows: the first player to complete the level receives $$$m$$$ points, the second receives $$$m-1$$$ points, and so on. Participants who do not complete the level, including those who give up, receive no points.
Your task is to output the current total points of each participant in descending order based on the log. If multiple participants have the same points, they should be listed in ascending order by their index.
The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 10^4$$$), indicating the number of test cases.
For each test case, the first line contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$1 \leq n \leq 10^5$$$, $$$2 \leq m \leq 10^5$$$, $$$1 \leq q \leq 2 \cdot 10^5$$$), indicating the number of levels, participants, and log messages, respectively.
The following $$$q$$$ lines contain the log messages as specified above. Of course, the messages are presented in chronological order. The log may not contain all levels, as you may receive it midway through the competition. You only need to process the current results.
It is guaranteed that the sum of $$$n$$$, the sum of $$$m$$$, and the sum of $$$q$$$ over all test cases do not exceed $$$5 \cdot 10^5$$$, respectively.
For each test case, output $$$m$$$ lines, each containing two integers: $$$id$$$ and $$$x$$$, where $$$id$$$ is the participant's index and $$$x$$$ is their total points, sorted in descending order of points. If multiple participants have the same points, list them in ascending order by their index.
33 4 61 22 1 12 2 23 3 22 3 22 1 23 4 81 22 1 12 2 23 3 22 3 22 1 21 12 1 13 4 71 22 1 12 2 23 3 22 3 22 1 21 1
2 4 1 3 3 0 4 0 1 7 2 4 3 0 4 0 2 4 1 3 3 0 4 0
| Name |
|---|


