Baltic Olympiad in Informatics: 2008 Day 1, Problem 1
Two players,
and
, play a game on a square board of size
. The squares of the board are either white
or black. The game is played only on the white squares — the black ones are excluded from the game. Each
player has one piece, initially placed at this player's starting point — one of the white squares on the board.
The starting point of
is different than that of
.
In each move a player moves his piece to one of the neighboring white squares (either up, down, left or
right). If the player moves his piece to the square currently occupied by his opponent's piece, he gets an extra
move (this way he may jump over the opponent). Note that in this case the direction of the second move can
be different than that of the first move.
Player
moves first, then players alternate. The goal of the game is to reach the opponent's starting point.
The player whose piece reaches his opponent's starting point first, wins the game. We want to determine
which player has a winning strategy (a player has a winning strategy if he can win regardless of his opponent's
moves).
Figure 1. If
moves to the right on his first three
moves,
will move up the first three moves. Thus,
on the third move player
will reach the square
with
's piece and will be allowed to move again.
Because of this,
will reach
's starting point first
and will win the game.
Figure 2.
can start by moving one step to the
right and one step down. Then, depending on the
first two moves of
, he will either go down or
right and evade
. This way
will reach
's starting point first, thus winning the game. In fact we
proved that
has a winning strategy.
Constraints


Subtask 1 [40%]

Subtask 2 [20%]

Subtask 3 [40%]
No additional constraints.
Input Specification
The first line of the standard input contains one integer
, the number of test cases.
Each test is described as follows. In the first line of the test there is one integer
, the length of the side of the grid. Then next
lines contain the description of the grid.
Each line consists of
characters (with no whitespace between them). Each character is either .
(a white
square), #
(a black square), A
(the starting point of
) or B
(the starting point of
).
You may assume that there exists a path of white squares between the starting points of
and
.
Output Specification
For each test case, output one line containing a single character A
or
B
, indicating the player who has a winning strategy.
Sample Input
Copy
2
4
A...
.#..
....
...B
4
A...
....
..#.
...B
Sample Output
Copy
B
A
Sample Explanation
See Figure 1 and 2 above.
Comments