Day 2 Question 1

Scoring Curling

Input file: curl.in

Output file: curl.out

The sport of curling is played in ends. In an end, two teams throw eight rocks each toward a circular target. The centre of the target is called the tee. The team that scores is the team whose rock is closest to the tee. The score for that team is the number of rocks belonging to it that are closer to the tee than any other rock from the opposing team, and no more than six feet from the tee. Rocks within .001 feet of the same distance to the tee are considered to be tied. A rock is not considered to be closer to the tee than a rock with which it is tied. If the nearest rocks for the two teams are tied or both more than six feet from the tee, the end is declared to be a blank end, and there is no score.

Assume that the tee is at at the location whose coordinates are (0,0). The position of each rock is given as coordinate pairs (x,y) where x and y are in feet. For each of several games you are to determine which team wins, and its score.

The Input

The input consists of a line containing an integer n, followed by the information for n ends of curling. For each end, the positions of the eight rocks for team A are given followed by the positions of the eight rocks for team B. Each position is given on two lines, the first being the x coordinate and the second being the y coordinate.

The Output

For each end, write a line containing the name of the team that wins (A or B) followed by a space followed by its score. If no team wins, write BLANK END.

Sample Input

1
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
0.1
1
0.9
-0.9
8
-8
-7
7
6
5
5
4
4
5
0
0

Output for sample Input

B 3