Problem Statement:
In A2OJ Code Battle, the scoreboard calculation isn't easy, so we're going to use this problem to teach you the exact rules, and your task is to generate a scoreboard given the submissions list.

For each submission you will be given the submission time (in minutes since the start of the contest), the contestant ID, the problem ID and the submission result. The scoreboard should contain how many problems were solved by each contestant, and the each contestant's time penalty.

The number of solved problems is easy to calculate, if a contestants makes 2 or more correct submissions for the same problem, it will be counted only once.

The time penalty for each contestant is the sum of the time penalty for each solved problem by this contestant. The time penalty for a solved problem is the time when the first correct submission was made + 20 for each wrong submission which happened before the first correct submission.

For example consider the following submissions made by one contestant:

  • Correct submission in problem 1 at minute 16.
  • Wrong submission in problem 2 at minute 19.
  • Wrong submission in problem 3 at minute 28.
  • Correct submission in problem 2 at minute 24.
  • Correct submission in problem 2 at minute 26.
  • Wrong submission in problem 2 at minute 28.
In the above example, the contestant solved problem 1 and its time penalty is 16, and problem 2 and its time penalty is 44 (24 + 20, because the first correct submission was after 24 minutes and there was a wrong submission before that). So the total time penalty for this contestant will be 60 (16 + 44).

Note that the submission in problem 3 didn't add any time penalty, because this problem wasn't solved, also the last submission didn't add any time penalty because it was made after a correct submission for that problem, and the time penalty for the first correct submission was used.

Also note that for technical reasons, the submissions won't be given for you sorted using the submission time.

Can you write a program to generate such scoreboard?

Input Format:
Your program will be tested on one or more test cases. The first line of the input will be a single integer T (1 ≤ T ≤ 100) representing the number of test cases. Followed by T test cases.

Each test case starts with a line containing 3 integers separated by a space, C (the number of contestants, the contestants will be numbered from 1 to C, 1 ≤ C ≤ 100), P (the number of problems, the problems will be numbered from 1 to P, 1 ≤ P ≤ 10) and S (the number of submissions, 1 ≤ S ≤ 1000).

Followed by S lines, each line represents a submission (the submissions are not sorted in the input in any way).

Each submission line contains 4 integers separated by a space, t (the submission time in minutes, 1 ≤ t ≤ 1000), c (the contestant ID, 1 ≤ cC), p (the problem ID, 1 ≤ pP) and r (r will be 0 which means wrong submission or 1 which means correct submission).

It's guaranteed that no 2 submissions will be made by the same contestant at the same time.

Output Format:
For each test case, print C lines, one line for each contestant and the lines should be sorted based on the number of solved problems (who solved more ranks higher) and in case of a tie in number of solved problems, the one with lower total penalty time ranks higher. Each line should contain 3 integers separated by a space, c (the contestant ID), X (the number of solved problems) and Y the total time penalty.

If 2 contestants or more have the same number of solved problems and the same total time penalty, sort them based on the contestant ID (the lower ID comes first).

Sample Input:
2 2 3 6 16 2 1 1 19 2 2 0 28 2 3 0 24 2 2 1 26 2 2 1 29 2 2 0 2 2 2 5 1 1 1 5 2 2 1

Sample Output:
2 2 60 1 0 0 1 1 5 2 1 5

Added by: ahmed_aly
Added at: 2017-10-09 20:00:00 UTC
Time Limit: 2 seconds
Partial score: No
Source:A2OJ Code Battle Round 1