Soccer League

No attempts yetTime limit1sMemory limit128 MB

Problem

Soccer, also called football, is the most popular sport in the world. According to a study published in 2001, more than 240 million people regularly play football in over 200 countries.

You have been hired to provide IT support for the Soccer League. The rules for this season are:

  • The club that wins a league match scores three points. If a match is drawn, each club in that match scores one point.
  • The results are kept in a table listing, for each club, the number of points it scored during the season.
  • Clubs are ranked by their total points: the club with the most points is at the top of the table and the club with the fewest points is at the bottom.
  • If two or more clubs have the same number of points, they are ranked by goal difference — the total goals a club scored minus the total goals scored against it during the season — with the larger goal difference ranked higher.
  • If two or more clubs have the same number of points and the same goal difference, they are ranked by the order in which they first appear in the input; a club that appears earlier is ranked higher.

Given a list of match results from the Soccer League, produce the league table defined by these rules.

Input

The input contains several test cases. The first line of a test case contains a single integer $N$, the number of matches in that test case ($1 \le N \le 1000$). Each of the next $N$ lines describes one match in the format

Club1 X x Y Club2

where Club1 and Club2 are strings of at most 15 characters (letters az and AZ), X is the number of goals scored by Club1, and Y is the number of goals scored by Club2 ($0 \le X \le 10$ and $0 \le Y \le 10$). The lowercase x between the two scores is a literal separator. The input ends with a line containing $N = 0$, which is not processed.

Output

For each test case, output its league table. Each line of a table has the format

P Club

where P is the number of points accumulated by Club. List the clubs in order of descending points. Clubs with equal points are ordered by descending goal difference. Clubs with equal points and equal goal difference are ordered by the order in which they first appear in the input (a club that appears earlier comes first). Separate consecutive league tables with a single blank line.