#Lutece0142. Board

Board

Migrated from Lutece 142 Board

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

In the Olympic days, we pay much attention on the medal-board. Now you should show us the board if we give you the result of all the matches.

In the board, the countries should be ordered by the gold medals. If a tie occurred, we will order them by the silver medals, if there is still a tie, we will compare them by the bronze medals. If two countries got the same medals in all the three scales, we will list them by lexicographic order of their names(you may assume that the countries' names won't be repeated).

Input

The first line of the input contains a number TT indicate the test cases.

For each test case,

You will get NN (1N10001\leq N\leq 1000) in the first line indicate the number of countries.

Then NN lines, each line contains a string indicate the ithi_{th} country’s name, no two country share the same name.

The next line you will get an integer MM (1M10001\leq M\leq 1000) denotes the number of items we have in the Olympic game.

Then MM items come, for each items, you will get 44 lines, the first line will be the name of this item, the next 33 line each give you the nationality of the players in this item from gold to bronze. You can assume the nationality is included in the above country names.

Each of the string above contains no more than 8080 letter (a to z and A to Z).

Output

For each test case, you should output the final medal-board, the countries should be ordered by rules mentioned above, the output format should the same with the sample, after each case, output a blank line.

Samples

1
3
China
USA
Russia
1
Football
China
USA
Russia
China 1 0 0
USA 0 1 0
Russia 0 0 1

Resources

Sichuan State Programming Contest 2008