Robots

We have a board n×mn \times m where each square is marked with a S, L, R, or E. Initially, a robot is placed in any square, looking at the north (N), east (E), south (S) or west (W). Repeteadly, the robot does two operations:

Write a program that indicates if the robot will go out of the board, it will explode or it will be moving in the board forever.

Input

The input consists of a natural t0t \ge 0 followed by tt test data separated by a line in white. Each test data consists of a line with nn and mm (both of them between 1 and 60), followed by nn lines with mm characters (S, L, R, or E) each one. Finally, the last line of each test data contains the initial row (a number between 1 and nn), and the initial direction (N, E, S or W).

Output

For each test data, your program must print “explodes”, “goes out”, or “does not go out” as required.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:14:31.829Z

© Jutge.org, 2006–2026.
https://jutge.org