Under construction

Still being built. Things may change

Basketball

Time limit1sMemory limit1024 MB

Summary
Given a log of score changes in two hoops, find the player who scored the most points and report that total.
Level

Easy2 of 10

Topics
Hash map, Implementation, String
Solved
No attempts yet

Problem

In Westeros there is a game that looks a lot like basketball. Tyrion Lannister cannot play it, but he enjoys following the game.

Westeros basketball is played by nn people. There are two hoops. Each player can shoot into either hoop and score one, two, or three points. Tyrion keeps a log. Each line records how the score changed and who made the basket. The score is two numbers, the points in the first hoop and the points in the second hoop, separated by a colon. A line in Tyrion's log can look like <<30:41 Lannister>>.

After the game, Tyrion wants to know who scored the most points. Managing the money of the realm takes most of his time, so he asks for help. The Lannisters always pay their debts, and you have every reason to help him.

Input

The first line contains the number of players nn (1≤n≤501 \le n \le 50).

Each of the next nn lines contains a player name sis_i (1≤∣si∣≤151 \le |s_i| \le 15). Names consist only of uppercase and lowercase Latin letters.

The line numbered n+2n+2 contains the number of Tyrion's records mm (1≤m≤5001 \le m \le 500).

Each of the next mm lines has the form <<aia_i:bib_i tit_i>>, without the angle brackets. Here aia_i is the points in the first hoop, bib_i is the points in the second hoop, and tit_i is the name of the player who made that score. Tyrion never miscounts, so every record is correct.

The starting score is 0:0.

Output

Print one line with the name of the player who scored the most points and the number of points that player scored. If several players are tied, print any of them.

Examples1

  1. Example 1

    Input
    3
    Stark
    Barateon
    Lannister
    4
    3:0 Stark
    3:2 Barateon
    4:2 Lannister
    7:2 Lannister
    
    Expected output
    Lannister 4