League Tables

Given each team's current record and a list of match results, update the records and print the table sorted by points, goal difference, goals scored, then name.

Easy3ImplementationSortingStringSimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

League football (also called soccer) has been played in England since 1888, and across most of Europe it is the most popular winter game, just as rugby is in New Zealand. English newspapers and many websites publish the latest results and the current table.

In the English league every team plays every other team both at home and away, and the team with the most points at the end of the season wins the title. A win is worth 3 points, and a draw is worth 1 point to each team. Teams level on points are separated by the larger goal difference, that is goals scored minus goals conceded. If the goal difference is level too, the team that has scored more goals is placed first.

You are given a list of teams with their current records, followed by a list of match results. Update the record of every team that has a result recorded, and print the table sorted by the rules below.

Input

The first line contains one integer TT (8T308 \le T \le 30), the number of teams in the league. The next 2×T2 \times T lines give the current record of each team, two lines per team, in this format:

<name>
<games played> <wins> <draws> <losses> <goals for> <goals against> <points>

The first line of a pair is the team name. A name is one or more words, may contain digits, uses only letters, digits and spaces, and is at most 30 characters long. The seven numbers on the second line are non-negative integers smaller than 150.

The next line contains one integer GG (0<GT/20 < G \le T/2), the number of recorded games. The next 4×G4 \times G lines give one game each, in this format:

<home team name>
<home team score>
<away team name>
<away team score>

Both teams appear in the list above. Each score is a non-negative integer smaller than 20.

Output

Print TT lines, one updated record per line. A line holds the team name, games played, wins, draws, losses, goals for, goals against and points in that order, separated by single spaces.

Update a record by adding the recorded results to it. The winner of a game adds 3 points to its previous total, and each team in a drawn game adds 1 point.

Sort the teams by points in descending order, then by goal difference in descending order, then by goals scored in descending order, then by team name in ascending order. Compare names after mapping uppercase letters to lowercase, one character at a time by ASCII code, so a space comes before a digit and a digit comes before a letter. Digits compare as characters and not as numbers, so "10 Bridges" comes before "9 Bridges".