Universal Cup Judging System

Universal Cup

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓
统计

As you might know, team programming competitions usually follow the same set of rules: there are $t$ participating teams of $3$ people each; $p$ problems, denoted by the first $p$ uppercase English letters; and $5$ hours to solve them using $1$ computer per team. To determine the final standings, teams are compared using the following criteria, in the order of importance:

  • A team with more solved problems is placed higher.
  • A team with a smaller penalty time is placed higher. The penalty time is defined as the sum of the following values over all problems solved by the team: the submission time from the start of the contest in minutes for the first successful solution, plus $20$ minutes for every incorrect solution before that successful submission.
  • A team with an earlier decisive submission is placed higher. A submission is decisive if it achieved the $n$-th solved problem for the team, where the team has solved exactly $n$ problems in total.

Recently, a big championship concluded, with medals awarded to the top $12$ teams. A team $T$ is said to have guaranteed its medal with the submission $S$ if, after removing all of $T$'s submissions that occurred after $S$, $T$ still receives a medal, but removing $S$ itself in addition causes $T$ to no longer receive a medal.

Given the log of submissions, find, for each of the awarded teams, when they guaranteed their medals.

Input

The first line contains one integer $T$ ($1 \le T$), denoting the number of test cases that follow.

The first line of a test case description contains two integers $p$ and $s$ ($1 \le p \le 26$, $13 \le s \le 10^5$): the number of problems and the number of submissions. Each of the next $s$ lines describes a submission in the format $\textit{team}\ \textit{problem}\ \textit{time}\ \textit{verdict}$, in the order they were received by the testing system.

  • $\textit{team}$ is a string of $1$ to $50$ characters, which can be lowercase or uppercase English letters, digits, or the characters '-', '_', '.' (the minus sign, underscore, dot). It denotes the name of the team that made the submission. No two teams have the same name, and every participating team made at least one submission.
  • $\textit{problem}$ is a single uppercase English letter. If it is the $i$-th letter in the alphabetical order, it indicates the submission was for the $i$-th problem of the contest. It is guaranteed that $1 \le i \le p$.
  • $\textit{time}$ is a $4$-character string in the format $\textit{h}\texttt{:}\textit{mm}$, where all characters except one are digits, denoting the elapsed time from the start of the contest: $h$ hours and $mm$ minutes ($0 \le h \le 5$, $00 \le mm \le 59$, $h \cdot 60 + mm \le 300$). It is guaranteed that, within a single test case, $\textit{time}$ for each submission is not less than $\textit{time}$ for the previous one. Note, however, that the equality of $\textit{time}$ doesn't imply that the submissions occurred simultaneously: the one listed earlier happened earlier.
  • $\textit{verdict}$ is a string of two uppercase English letters. The submission was correct if and only if the verdict is OK. For the purposes of this problem, there are no verdicts that are ignored when calculating the penalty time (for example, CE also counts as an incorrect attempt).

It is guaranteed that at least $13$ teams solved at least one problem, the sum of $s$ across a single file does not exceed $10^5$, and the sum of all $|\textit{team}|$ across a single file does not exceed $10^6$.

Output

For each team that received a medal, print a single line with two strings: the team name and the time of the submission that guaranteed its medal, in the format $\textit{h}\texttt{:}\textit{mm}$. List the teams in the same order as their guaranteeing submissions appear in the input.

Example

Input

1
3 34
Lucky_I_of_Tech C 0:01 WA
Abbr._U_of_Tech A 0:15 OK
Bioinformatics_U A 0:20 OK
M._University A 0:30 OK
UN_de_Ingenieria A 0:35 OK
College_No_1234 A 0:40 OK
Discrete_Math_U A 0:45 OK
Ecole_Perpendiculaire A 0:50 OK
FFT_University A 1:00 OK
Great_Staff_U A 1:11 OK
Hard_Problems_U A 1:20 OK
Lucky_I_of_Tech B 1:30 OK
Never_Medal_U A 1:30 OK
Lucky_I_of_Tech B 1:30 OK
Unfreezing_U A 1:40 OK
Lucky_I_of_Tech B 1:40 TL
Univ._of_Toyoko A 2:11 OK
Univ._of_Toyoko B 2:50 RE
Univ._of_Toyoko B 2:50 ML
Univ._of_Toyoko B 2:51 WA
Univ._of_Toyoko B 2:51 OK
Bioinformatics_U B 3:49 OK
Abbr._U_of_Tech B 3:50 OK
M._University B 3:59 OK
UN_de_Ingenieria B 4:00 OK
College_No_1234 B 4:10 OK
Discrete_Math_U B 4:12 OK
Ecole_Perpendiculaire B 4:14 OK
FFT_University B 4:16 OK
Great_Staff_U B 4:18 OK
Hard_Problems_U B 4:25 OK
Lucky_I_of_Tech A 4:32 OK
Never_Medal_U B 4:32 OK
Unfreezing_U B 4:59 OK

Output

Univ._of_Toyoko 2:51
Bioinformatics_U 3:49
Abbr._U_of_Tech 3:50
M._University 3:59
UN_de_Ingenieria 4:00
College_No_1234 4:10
Discrete_Math_U 4:12
Ecole_Perpendiculaire 4:14
FFT_University 4:16
Great_Staff_U 4:18
Hard_Problems_U 4:25
Lucky_I_of_Tech 4:32

Note

In the example, Lucky_I_of_Tech, Univ._of_Toyoko, and Never_Medal_U are tied with $2$ solved problems and $362$ minutes of penalty time. However, Never_Medal_U submitted their second successful solution later than the two other teams, so they did not receive a medal.

Note that, for the purposes of this problem, the competition rules may differ slightly from those used in the actual ICPC World Finals or any of its regional competitions.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.