cswork / OAOpen practice workspace

Goldman SachsOA #8

Encircular

EasyJudge-ready

Topics (AI-labelled)SimulationBits & Math

A robot starts at coordinates (0,0) facing north and executes the commands G (move forward one step), L (turn left in place), and R (turn right in place). The command string repeats forever. Determine whether the robot's path always stays bounded; output YES if it is bounded, otherwise output NO.

Input

The first line contains n (1..10), followed by n lines, each containing a command string of length 1..2500 consisting only of G, L, R.

Output

For each command string, in input order, output YES or NO, one result per line.

Example 1

Input:

3
G
GL
GRGRGRGR

Output:

NO
YES
YES

Example 2

Input:

1
R

Output:

YES

Example 3

Input:

1
GLGLGLGL

Output:

YES

Editorial

Loading solution…