It's time for a new Formula 1 race, and the board of directors decided that it's also time for a new chronometer system. They bought all the ultramodern radar-laser-microwave sensors to install in the starting line but just realized the manufacturer didn't provide the software to rank the cars.
That's how you come to the game. The board of directors wants you to write a program that receives the time each pilot spent on their qualification lap and prints the starting grid for the race (i.e., the order in which the pilots must start the race). And they want it fast! I bet you can do it in the time of a pit stop!
(If you don't know the rules that make the starting grid in Formula 1, consider that the less time the pilot spends on the qualification lap the better, i.e., the closer he will start to the beginning of the grid).
The input contains several input sets. The description of each set is given below:
Each set starts with one integer N (1 ≤ N ≤ 100), the number of participant pilots in the race, in the first line. Then, N lines in the format “S : X min Y sec Z ms” will follow (quotes for clarity only). The value S represents the name of the pilot and consists of 1 to 20 letters. The integers X (0 ≤ X ≤ 59), Y (0 ≤ Y ≤ 59), and Z (0 ≤ Z ≤ 999) represent the number of minutes, seconds, and milliseconds, respectively, that the pilot spent on his qualification lap.
There is a blank line after each input set. The input is terminated by EOF.
For each input set, your program must produce the starting grid, i.e., the order in which the pilots must start the race, in the following format: For each row in the grid (a pair of cars that start the race side by side), print a line containing “Row R”, where R represents the row number starting from 1, followed by two other lines containing the names of the pilots (as they appear in the input) that start the race from that row (in order of classification). If a row contains only one pilot, just print one line after the row number. If there are two pilots with the same name in a test case, they are different pilots, and the output must contain both of them. If two or more pilots are tied in the classification time, sort them by their names (lexicographically, case-insensitive comparisons). Print a blank line after each test case.
Output for Sample Input
|University of Debrecen; Faculty of Informatics; v. 03/19/2018|