Petanque

No attempts yetTime limit1sMemory limit128 MB

Problem

Petanque, a game played with metal balls (several boules and one small target ball called the coche), is simple in spirit. Just as football is about kicking the ball into the opposing goal while keeping it out of your own, petanque is about placing your boules nearer to the coche than your opponent can.

We consider a simplified two-player version. The players stand on a flat plane and each has three boules. One player starts the game by throwing the coche forward, and the same player then throws the first boule. The opposing player throws the second boule. From then on, the next boule is always thrown by the player who does not currently own the boule nearest to the coche (you may assume that, at each such moment, exactly one boule is nearest to the coche). This continues until one player has thrown all three of their boules; the other player then throws all of their remaining boules.

The winner is the player who owns the boule that ends up nearest to the coche (again, assume exactly one boule is nearest at the end). The winner scores one point for each of their own boules that lies closer to the coche than every one of the opponent's boules.

You must simulate several games. Treat the playing floor as a plane and every ball as a dimensionless point. You are given the two players' names; the first name listed plays first. For each ball thrown (the coche or a boule) you are given its starting position, its direction, and how many meters it rolls. You may assume that every starting position lies inside the floor, that no ball ever leaves the floor, and that a ball's starting position never coincides with the current position of another ball. Directions are given in degrees, measured counter-clockwise from the positive x-axis (east = 0 degrees), as illustrated below.

Illustration of the direction of the balls

When a rolling ball reaches another ball lying in its path, the rolling ball stops at that point and the ball it struck starts rolling in the same direction. The struck ball rolls exactly the number of meters the moving ball still had left to roll (this remaining distance is never zero). If the struck ball in turn reaches yet another ball, the same rule applies again (again, the remaining distance is never zero).

Input

The first line contains an integer $N$, the number of test cases ($1 \le N \le 10000$).

Each test case consists of eight lines. The first line contains the names of the two players separated by a single space; the first name plays first. A name consists of at most 20 letters from the English alphabet (A-Z, a-z).

The next seven lines describe the seven balls in the order they are thrown: first the coche, then the six boules thrown by the players according to the rules above. Each of these lines contains four integers $X$, $Y$, $\theta$, and $D$: the ball's starting position ($-1000 \le X, Y \le 1000$), its direction in degrees ($0 \le \theta \le 360$), and the distance it rolls if nothing blocks its way ($0 < D \le 100$).

Output

For each test case, print a single line containing the name of the winning player and the number of points they scored, separated by one space.