We have a board n × 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 t ≥ 0 followed by t test data separated by a line in white. Each test data consists of a line with n and m (both of them between 1 and 60), followed by n lines with m 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 n), 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.
Input
5 1 4 XSSS 1 4 W 4 5 XXRSR SSLXS XXXXS XXLSR 2 1 E 2 2 RR RR 1 1 N 2 3 XLL SSL 2 1 E 1 1 X 1 1 S
Output
explodes explodes goes out goes out explodes