Problem hidden

TWOKINGS - TRIVIADOR


TRIVIADOR

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 ones). All the 8 regions around any region are connected to 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 Specification:

The first line is an integer t, denotes the number of test cases. In each test case the first line consists of two integers denoting the number of rows and columns in 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.


Output Specification:
For each test case output the result in a single line ‘X’ if king1 wins or ‘O’ if king2 wins.

 

Input Constraints:

T<=100

1<=rows,columns<=10

 

Sample input:


3

3 3

XOX

XXX

XOX

 

3 5

XXXXX

XXXOO

XXXOO

 

4 4

XXXX

OOOO

XXXX

OOOO


Sample Output:

O

X

X

 

Explanation of testcase 1 and 2:

Case 1: King1 has two possibilities to attack. But after attacking any of them, he will lose surely when king2 attacks back.

Case 2: King1 can attack any of the four enemy positions. He conquers all the connected enemy positions. So this is a one step victory.


Try the 1D version of this problem : http://spoj.com/problems/QWERTY04/
Try the 3D version of this problem : http://spoj.com/problems/CONQUER/


Adicionado por:cegprakash
Data:2012-01-02
Tempo limite:1s
Tamanho do fonte:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Linguagem permitida:Todas exceto: ASM64 CLOJURE ERL FSHARP PERL6 PY_NBC SCALA TCL
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.