Welcome to ZOJ
64 - The 8th Zhejiang University Programming Contest - 1007
Golf Rank

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Golf is a sport in which a player, using several types of clubs, hits a ball into each hole on the golf course in the lowest possible number of strokes.
A hole is classified by its par, the number of strokes a skilled golfer should require to complete playing to the hole. For example, a skilled golfer expects to reach the green on a par-four hole in two strokes, one from the tee (the "drive") and another stroke to the green (the "approach") and then roll the ball into the hole with two putts.
Scores for each hole can be described as the strokes made by the player (possibly with some penalties for O.B. and water hazard) to hit the ball into the hole subtracting the par of the hole. For example, one finishes a par-four hole with three strokes will get a score of -1 (also known as Birdie), while another finishes the same hole with five strokes will get a score of +1 (also known as Bogey). Obviously the aim of all players is to make a lowest score.

In a golf tournament, several players play on the same course simultaneously and separately, and their scores are recorded for each hole. It does not matter how long it takes you to finish all the holes, only the total score you get from all the holes matters. So when you're playing the 4th hole, someone may just start to play the first hole, while another one may have finished all the nine holes. For this reason, the rank list of golf is somewhat different from those in other games: players are ranked even though they're playing different holes. The rank list contains all the statistics of the players and is updated every time a player finishes a hole. Your task here is to read the information of a golf course, together with the strokes made by different players to finish each hole in order, print the current rank list on demand.


Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 150) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case represents a golf tournament and begins with a line with a positive integer H, the number of holes in this course (H <= 18). The second line contains H integers Pi, the par of each hole in the course (3 <= Pi <= 5, 1 <= i <= H). Then follow several lines with either the format "Name Strokes" or a string "ShowRank". A line with the format "Name Strokes" indicates the player Name has just finished a hole with Strokes strokes, where Name is the name of this player with no more than 10 letters (won't be "ShowRank"), and Strokes is a positive integer less than 10. A line with a string "EndOfTournament" indicates the end of this tournament. You may assume all players appear before will finish (exactly) all the H holes by then, and at most 100 players will participate in a tournament.

There's an empty line between every two contiguous cases as well as between T and the first test case.


For each tournament, print a line of "Tournament K" at the beginning, where K is the number of this tournament (starts from 1).

For each "ShowRank" string, you should print the current rank list with the following format:

Place  Name        Score  Holes

The first column contains the places of players ranked according to their scores at present (while players with the same score will share the same place, of course); the second column contains the names of players; the third column contains the scores of players at present; and the last column contains the number of holes players have finished (except when a player has finished all the holes, use 'F' instead of the number of holes). The four columns take 5, 10, 5 and 5 spaces of characters, respectively, while there're two blank spaces between every two adjacent columns. (Just as the digits in the first row show and those digits will not be in the actual output) Places, scores and holes of players should be right aligned to the 5th, 24th and 31st characters, respectively, while names of players should be left aligned to the 8th character. Print a blank line after each rank list. (Refer to the sample output)

The players should be sorted by their scores in ascending order. Players with the same score should be sorted by their average scores among the holes they played in ascending order. (This also shows the chance of win for those players, since when two players have the same negative score, the one who has finished less holes is likely to win when he finishes all the holes, vice versa.) For the players with the same score and the same average score, just sort them with their names alphabetically.

Sample Input


4 5 3
Alpha 3
Bravo 5
Charlie 4
Charlie 3
Bravo 4
Charlie 2
Alpha 4
Alpha 2
Bravo 3

Sample Output

Tournament 1
Place  Name        Score  Holes
    1  Alpha          -1      1
    2  Bravo          +1      1

Place  Name        Score  Holes
    1  Charlie        -3      F
    2  Alpha          -1      1
    3  Bravo           0      2

Place  Name        Score  Holes
    1  Alpha          -3      F
    1  Charlie        -3      F
    3  Bravo           0      F

Submit    Status