#K88752. Robot Return to Origin

    ID: 37378 Type: Default 1000ms 256MiB

Robot Return to Origin

Robot Return to Origin

Given a series of command sequences containing the characters L, R, U, and D, determine if a robot returns to the origin after executing all commands. The robot starts at \( (0, 0) \). Each command affects the robot's position as follows:

  • L: Move left (\( x \) decreases by 1).
  • R: Move right (\( x \) increases by 1).
  • U: Move up (\( y \) increases by 1).
  • D: Move down (\( y \) decreases by 1).

If after executing all commands the robot is at \( (0, 0) \), output YES, otherwise output NO.

Note: An empty command sequence indicates that the robot does not move and remains at the origin.

inputFormat

The first line of the input contains an integer \( T \) denoting the number of test cases. Each of the following \( T \) lines contains a string representing the sequence of commands. The command string may be empty.

outputFormat

For each test case, print a single line containing YES if the robot returns to the origin \( (0, 0) \) after executing the commands, or NO otherwise.

## sample
3
LR
UDDDRLLU
LRRR
YES

NO NO

</p>