Baseball is a game full of statistics, and those statistics can be used to predict the outcome of a game.
A game consists of 9 innings. If the score is tied after 9 innings, one extra inning is played at a time until the score is no longer tied at the end of an extra inning. Each inning has two halves: the visiting team attacks in the first (top) half and the home team attacks in the second (bottom) half. If the home team is already ahead at the start of the bottom of the 9th inning, the game ends immediately because the winner is already decided.
Each team submits a batting order listing the sequence in which its 9 players bat. In every half inning the attacking team's players bat in this order. The first batter of the very first inning is the first player in the order; each following batter is the next player in the order, and after the last player the order wraps back to the first. At the start of every later inning, the first batter is the player who follows the last batter of that team's previous turn.
When a batter gets a hit, the batter reaches first base and every runner already on base advances exactly one base (a runner never advances more than one base in this problem). A runner must touch first, second, third, and finally home base to score a run; once a runner reaches home, that player returns to the bench. A half inning continues until 3 batters of the attacking team are out. When the third out occurs, any runners still on base do not score. The team with more runs at the end of the game wins.
In some situations a batter may sacrifice to advance the runners already on base. A successful sacrifice puts the batter out, but every runner already on base advances one base; a runner reaching home this way scores a run, unless the sacrifice is the third out of the half inning, in which case the half ends and no run scores. An unsuccessful sacrifice puts the batter out and no runner advances. A batter attempts a sacrifice whenever there is a runner on second base with no outs, or a runner on third base with at most one out.
Each player has a hit percentage (between 0 and 1), the fraction of at-bats in which the player gets a hit, and a sacrifice percentage, the fraction of attempts in which the player's sacrifice succeeds. Given the hit percentage, the sacrifice percentage, and the batting order of all 9 players on both teams, simulate one game. The simulation uses this random number generator:
$$x_{n+1} = (x_n \times 25173 + 13849) \bmod 65536$$
where $x_n$ is the previous random number and $x_{n+1}$ is the next one; all arithmetic uses 32-bit integers. Start from the seed $x_0 = 1$, so the first random number produced is $x_1$. Each time the simulation must decide whether a hit or a sacrifice succeeds, it generates the next random number. A hit (or sacrifice) succeeds when
$$x_{n+1} / 65536 \le \text{(hit or sacrifice percentage)}$$
using floating-point division. Do not reset the generator (that is, do not reset the seed to 1) except at the very beginning of each game.
The first line contains the number of games. Each game gives the batting order of the visiting team followed by the batting order of the home team. Each batting order starts with a line holding the team name (at most 15 upper- and lower-case letters). The next 9 lines describe the 9 players in batting order. Each such line contains the player's name (at most 15 upper- and lower-case letters), a space, the player's hit percentage (3 decimal places), a space, and the player's sacrifice percentage (3 decimal places). Every hit percentage lies between .200 and .400, and every sacrifice percentage lies between .300 and .750. No game lasts more than 200 innings.
For each game, print the game number together with the visiting and home team names on the first line:
Game <x>: <visiting> vs. <home>
followed by a blank line.
Then, for each inning in the order it occurs, print the players who got hits and the players who scored runs. Use this format:
Inning 1:
Hits:
<player1> <team>
<player2> <team>
Runs:
<player3> <team>
<player4> <team>
Indent each player list by two spaces. Print the player name and the team name right-justified in a field width of 15 (in addition to the two-space indentation before the name and one space separating the name from the team). If nobody gets a hit or scores a run, print the single line
none
(indented by two spaces) in that section instead of a list of players. Print a blank line after each inning.
At the end of the game, print a summary of the runs and hits for each team, visiting team first:
End of Game:
<visiting> <x> runs, <x> hits
<home> <x> runs, <x> hits
Indent the summary by two spaces and print each team name right-justified in a field width of 15 (in addition to the indentation). Separate the output of consecutive games with a line containing 60 '=' characters.