Welcome to ZOJ
 Contests Information Problems Runs Statistics Ranklist Clarification
44 - Andrew Stankevich's Contest, Warmup - 1007
Ranking

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

In this problem you are asked to implement the ranking system for a series of programming contests.

Each contest runs using standard ACM ICPC rules, each run is judged and either accepted, or rejected. For each solved problem the penalty time is calculated as the time of the first accepted run in minutes plus twenty minutes for each unsuccessful run before the first successful run. For problems that are not solved no penalty time is considered. The teams are first ranked by the number of solved problems, next by the penalty time. Each team gets the highest possible rank, that is, if two or more teams have the same number of solved problems and the same penalty times, they all share the same place, highest from the range they occupy. So, for example, there can be two teams sharing the first place, followed by the third place team, and so on.

The ranking of each team for the series of the contests is calculated as follows. Let Pij be the number of problems solved by j-th team in the i-th contest. Let PMi be the maximal number of problems solved by some team in the i-th contest. The raw score of the j-th team for this contest is RSij = Pij/PMi if PMi > 0 and RSij = 0 if PMi = 0. Let Ki be the number of teams take part in the i-th contest. Calculate Ai and Bi, satisfying equations

If the j-th team is ranked Rij in the i-th contest, its score for this contest is
If the j-th team took part in Cj > 0 contests, its total score is

in the other case its total score is Tj = 0.

Given the description of several contests, your task is for each team to calculate its total score.

Input

The input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 20) which is the number of test cases. T test cases follow, each preceded by a single blank line.

The first line of each test case contains N - the number of teams (2 <= N <= 100), next N lines contain team names, length of each name does not exceed 100 characters. Let teams be numbered as they are given in the input file, starting from one.

Next line contains M - the number of contests in a series (1 <= M <= 20). The descriptions of the contests follow. The first line of the contest descrption contains Ki - the number of teams that took part in this contest (2 <= Ki <= N) and the numbers of these teams. Next line contains PNi - the number of problems in the contest (1 <= PNi <= 26). Problems are identified using capital letters of the English alphabet, starting from 'A'. Next line contains RNi - the number of runs in the contest (0 <= RNi <= 10 000). Next RNi lines describe runs, each run description consists of four items, adjacent items are separated from each other by exactly one space. The items are: the number of the team, the letter of the problem, the time of the run in minutes and character '+' if the run is accepted, or '-' if it is rejected. Runs are given in the order they were made, in particular run times are non-decreasing. Times are positive integers that do not exceed 300.

Output

For each test case, output N lines - the teams in the non-increasing order of their total score. In case of equal total score, teams may be output in arbitary order. Print score aligned, so that there is exactly one space between the longest team name and the leftmost digit of the score, and all decimal points are in the same column. Print exactly four digits after the decimal point.

Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

Sample Input

```1

4
MosCow SU
ThreeThreads
SPb IMHO
SPb FLY
3
3  1 2 3
5
10
1 A 30 +
1 B 80 +
2 A 85 -
2 C 90 +
1 E 101 +
3 A 130 -
3 A 140 +
1 D 150 +
3 D 280 +
3 E 299 +
2  2 3
2
3
2 A 160 +
2 B 245 +
3 A 280 +
3  1 3 4
4
6
1 A 50 +
3 A 50 +
1 A 155 -
3 A 160 +
1 B 180 -
4 A 200 -
```

Sample Output

```MosCow SU    2.0000
SPb IMHO     1.1667
ThreeThreads 1.1250
SPb FLY      0.0000
```

Author: Andrew Stankevich

Submit    Status