A Duckpin Tournament

Time Limit: 1 Second    Memory Limit: 32768 KB

In a Duckpin Tournament, the winner is decided by the player with the highest number of tournament points earned by playing a number of matches. Points are awarded for winning a match and scoring the highest game during the match. A duckpin match consists of a series of three lines, or games. The match winner is the player with the highest series score, i.e., three game total. The high game winner is the player with the highest score for a single line during the match.

A line of duckpins is divided into ten frames. In each frame a player has three tries to knock down ten duckpins with a ball. If the player knocks down all ten pins on the first try, a strike is awarded and the frame is concluded (see exception below). If the player knocks down all ten pins in two tries, a spare is awarded and the frame is concluded (see exception below). If during any of the three tries a foul is committed by the player crossing the foul line, the frame is concluded and only the pins knocked down prior to that try are counted for the frame.

The points earned in a frame equal the number of pins knocked down plus any bonus points earned for a spare or a strike. The bonus points earned for a spare or strike equal the number of pins knocked down on the next try following a spare or on the next two tries following a strike. A foul following a spare or strike earns zero bonus points unless the foul occurs on the second try following a strike; then only the bonus points earned on the first try are counted.

A spare or a strike normally concludes the frame. However, if a spare or a strike occurs in the tenth frame, the frame is concluded by the player immediately taking the appropriate number of tries to earn the bonus points. The score for each frame equals the number of points awarded for the frame plus the score in the previous frame.

Write a program to produce a scoring summary for one or more duckpin matches of one to four players.

Input

The input for each match consists of an integer indicating the number of players, a list of players' names (each name is a max. length of 10 alpha characters), followed by lines of integers representing the number of pins knocked down by each player on the first, second, or third try in each game in the match. The match is concluded by `#'. The input is concluded when the number of players for a match is zero.

Since each match consists of three games and each player gets three tries per frame in each game, the total number of lines of integers in the match will be nine times the number of players. The players play in the order that the names were listed. The order of the lines is:

1. three lines for the first player in the first game followed by three lines for each of the other players for the first game,

2. three lines for the first player in the second game followed by three lines for each of the other players for the second game,

3. similarly for the third game with the match concluded by `#'.

The line of integers representing the first try will have at least ten integers but no more than twelve. Since a second or third try may not be attempted in a frame, the second and third lines may have less than ten integers.

A negative integer indicates the number of pins knocked down however the player fouled on the try.

Output

The output shows a frame by frame score for each player for each game in the match. Each line of output consists of the player's name, left justified in a field ten characters wide, and ten integers, right justified with a field four characters wide. At the end of the match report the match and high game winner followed by a blank line.

No two players will get the same high score.

Sample Input

3
Tim Jim Bob
5 7 8 5 10 10 10 8 9 10 10 10 (scores for Tim's first game)
5 2 1 4 1 0
0 1 1 1 1
10 10 9 8 9 9 10 9 9 9 8 (scores for Jim's first game)
1 1 1 0 1 1 1
1 1
7 6 8 9 -10 8 9 8 10 10 8 1 (scores for Bob's first game)
3 2 2 1 1 1 1
2 1 1
0 8 8 8 9 7 6 -6 7 9 (scores for the second game)
6 1 2 1 0 1 3 3 0
3 0 1 1 1 0 0
5 7 10 9 8 9 10 7 8 9 7
5 3 1 2 1 -3 2 1 (blank line shows no 3rd
tries were used in this game)
9 8 9 8 9 7 10 9 9 9
1 1 1 2 1 2 0 1 0
1 1 1 1
5 6 7 8 9 10 10 -10 10 10 10 10 (scores for the third game)
4 2 3 1 1
0 2 1
8 7 6 10 9 9 10 7 8 6
2 2 3 1 0 3 1 3
1 0 1 1 1
9 8 9 9 9 8 10 10 10 8
1 2 1 1 1 2 1
1
#
0

Sample Output

Tim 17 26 36 46 76 104 123 133 143 173
Jim 29 49 67 77 96 106 126 145 164 182
Bob 16 26 45 55 55 65 83 93 121 140
Tim 9 18 36 46 56 65 74 74 93 102
Jim 17 37 57 75 94 114 131 138 157 174
Bob 18 28 46 65 82 92 111 121 140 150
Tim 9 19 37 47 67 87 97 97 127 157
Jim 17 27 36 56 75 85 105 123 133 143
Bob 18 37 56 75 93 113 143 171 190 200
Jim has the high series score of 499.
Bob has the high game score of 200.
Submit

Source: Pacific Northwest 1997