#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
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
For each test case output the result in a single line ‘X’ if king1 wins or ‘O’ if king2 wins.
Constraints
T ≤ 100
1 ≤ rows, columns ≤ 10
Example
Input: 3 3 3 XOX XXX XOX 3 5 XXXXX XXXOO XXXOO 4 4 XXXX OOOO XXXX OOOO</p>Output: O X X
Explanation of Test Cases 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.
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
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
For each test case output the result in a single line ‘X’ if king1 wins or ‘O’ if king2 wins.
Constraints
T ≤ 100
1 ≤ rows, columns ≤ 10
Example
Input: 3 3 3 XOX XXX XOX 3 5 XXXXX XXXOO XXXOO 4 4 XXXX OOOO XXXX OOOO</p>Output: O X X
Explanation of Test Cases 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: