URI Online Judge | 2595

Cash Roial

By Abner Samuel P. Palmeira, IFSULDEMINAS BR Brazil

Timelimit: 2

Cash Roial is a very popular mobile game, which is available for Ciborgue and AOS (Aifone OS) phones. The game is played by two players, who summon troops in an arena to defeat the opponent.

Irineu likes to play Cash Roial, but currently he has not achieved many victories, so he asked for your help. Irineu knows how the arena is right now, he wants to summon a troop at the position (X, Y) and know if it will be defeated or not. A troop is defeated if there are at least five enemy troops in adjacent positions.

The position in the upper left corner represents the coordinates (1,1) and the position in the lower right corner represents the coordinates (N,M).


The first line contains an integer C that represents the number of test cases.

The first line of each test case contains three integers N, M and P, indicating respectively the number of rows, the number of columns in the arena, and the number of questions. Each of the N following lines of the entry describes a cell line of the arena and contains a string with characters M. The next P lines contain two integers X, Y indicating the location that Ireneu wants to put a troop.

Each cell in the arena can contain one of the following characters:

'.' - empty cell.

'T' - cell containing an enemy troop.

(1 ≤ N ≤ 1000)

(1 ≤ M ≤ 1000)

(1 ≤ P ≤ 1000)

(1 ≤ X ≤ N)

(1 ≤ Y ≤ M)


For each question of Ireneu, write "GG IZI" if the troop will live and "GRRR" otherwise.

Input Sample Output Sample

8 8 2
5 4
6 2