Ranking List

Time limit1sMemory limit128 MB

Summary
Build a contest scoreboard: rank teams by solved problems then total time, with ties sharing a rank and listed alphabetically.
Level

Medium4 of 10

Topics
Sorting, Implementation, Simulation
Solved
No attempts yet

Problem

Write a program that produces the ranking list for a programming contest. You are given the list of participating teams and a log describing every solution the teams submitted.

Scoring follows these rules:

  1. Teams are ranked by the total number of problems they solved correctly (more solved problems is better).
  2. Teams that solved the same number of problems are ranked by least total time.
  3. The total time is the sum of the time consumed over each solved problem. The time consumed for a solved problem is the number of minutes from the start of the contest until the accepted submission, plus 20 penalty minutes for every rejected submission for that problem (regardless of when the rejected run was submitted). A problem that is never solved consumes no time.

The detailed tie-break procedure for equal total times is intentionally not part of this task. Instead, if two or more teams have both the same number of solved problems and the same total time, assign them the same rank and list them in alphabetical order.

A team's rank rr means that exactly r−1r-1 teams did better, so ranks are skipped whenever a tie occurs. For example, if the two best teams have identical solved counts and total times, they both receive rank 11 and the next team receives rank 33 — no team is assigned rank 22.

Finally, there is no penalty for a rejected submission made after a correct submission has already been accepted from the same team for the same problem.

Input

The first line contains the number of scenarios.

Each scenario begins with a line containing the number nn of teams (1≤n≤201 \le n \le 20), followed by nn lines with the teams' distinct names, given in alphabetical order. A team name is a single word of at most 8 characters containing only letters and digits.

The next line contains the number kk of problems and the number mm of submitted solutions (1≤k<101 \le k < 10, 0≤m≤20000 \le m \le 2000). Each of the following mm lines describes one submission in the format problem time correctness team, where 1≤problem≤k1 \le problem \le k is the problem number, 0≤time<3000 \le time < 300 is the number of minutes elapsed since the contest started, correctness is either Yes or No, and team is the name of the submitting team. The submissions are sorted by time.

Output

For each scenario, print a ranking list containing every participating team. Each line has the format rank. team solved time, where rank is the team's rank, team is its name, solved is the number of problems it solved, and time is its total time.

The four fields are separated by single spaces and use fixed field widths: 2 for the rank, 8 for the team name, 1 for the number of solved problems, and 4 for the total time. Names are left-adjusted and numbers are right-adjusted (see the sample output).

Separate the ranking lists of consecutive scenarios with a blank line.

Examples3

  1. Example 1

    Input
    2
    10
    Team1
    Team2
    Team3
    Team4
    Team5
    Team6
    Team7
    Team8
    Team9
    slowTeam
    8 14
    1 18 Yes Team4
    1 57 Yes Team2
    1 87 Yes Team3
    1 101 Yes Team1
    2 103 Yes Team5
    2 120 Yes Team6
    6 141 Yes Team7
    1 147 No Team1
    7 156 Yes Team2
    5 167 Yes Team8
    2 167 Yes Team9
    5 170 No Team4
    5 175 Yes Team4
    1 234 No slowTeam
    1
    Team1
    8 0
    
    Expected output
     1. Team2    2  213
     1. Team4    2  213
     3. Team3    1   87
     4. Team1    1  101
     5. Team5    1  103
     6. Team6    1  120
     7. Team7    1  141
     8. Team8    1  167
     8. Team9    1  167
    10. slowTeam 0    0
    
     1. Team1    0    0
    
  2. Example 2

    Input
    1
    1
    Alpha
    1 1
    1 5 Yes Alpha
    
    Expected output
     1. Alpha    1    5
    
  3. Example 3

    Input
    1
    1
    Beta
    2 3
    1 10 No Beta
    1 20 No Beta
    1 30 Yes Beta
    
    Expected output
     1. Beta     1   70