CONQUER - TWO KINGS

Triviador is a war between two Kings.

A king can attack an enemy region at each step. When a king attacks a region, he conquers all the enemy regions connected to it (not just the immediate neighbours). Every region is connected to all the regions that share an edge or a corner with it. The kings get alternate chances to attack. King1 gets the chance to attack first. Assume both kings are intelligent and find who will conquer the whole territory at the end of the war. It can be proved that one of the kings can win for sure if he is intelligent!

Input

The first line consists of an integer t, which denotes the number of test cases. For each test case the first line consists of three integers a, b, c denoting the dimensions of the territory (each cell is a region). Then the description of each cell follows. Every region contains a character ‘X’ if it is owned by King1 or ‘O’ otherwise.

The description of the a×b×c 3D matrix is represented by 'a' b×c 2D matrixes.

Output

For each test case output the result in a single line ‘X’ if King1 wins or ‘O’ if King2 wins.

Constraints

1 ≤ t ≤ 50

1 ≤ a, b, c ≤ 50

Example

Input:
3
2 3 5
OXOOO
OOXXX
XXXXO
        <- empty line just for clarity.
XOXOO
XOOXO
OXXOX
1 1 6
OXOXXO
1 1 3
OOO

Output:
X
O
O

Explanation

Case 1: King 1 wins in his first move by attacking any enemy region.

Case 2: King 2 can win if he is intelligent.

Case 3: King 2 already won.

Try:

  • the 1D version of this problem : QWERTY04.
  • the 2D version of this problem : TWOKINGS.


Added by:cegprakash
Date:2013-01-15
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: BF

hide comments
2021-10-05 22:22:41 David
Yes! Only (current) Java solution.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.