#K66472. Vacuum Cleaner Navigation

    ID: 32428 Type: Default 1000ms 256MiB

Vacuum Cleaner Navigation

Vacuum Cleaner Navigation

You are given a sequence of commands, each represented by one of the characters 'U', 'D', 'L', and 'R'. Starting from the origin \((0, 0)\), each command moves the vacuum cleaner one unit in the specified direction:

  • 'U' increases the \(y\)-coordinate by 1.
  • 'D' decreases the \(y\)-coordinate by 1.
  • 'L' decreases the \(x\)-coordinate by 1.
  • 'R' increases the \(x\)-coordinate by 1.

If the command sequence is empty, the vacuum remains at \((0, 0)\). You are required to process multiple test cases. For each test case, compute and output the final coordinates \((x, y)\) after executing all commands.

Note: The final position is computed using the formula:

\[ x = \sum_{i=1}^{n}\Delta x_i, \quad y = \sum_{i=1}^{n} \Delta y_i \]

inputFormat

The input is read from standard input (stdin) and it follows this format:

  1. An integer \(T\) representing the number of test cases.
  2. \(T\) lines follow; each line contains a string of characters representing the sequence of commands.

Example:

3
UDLR
UUU
LLDDRR

outputFormat

For each test case, output the final \(x\) and \(y\) coordinates separated by a space on a new line, using standard output (stdout).

Example:

0 0
0 3
0 -2
## sample
3
UDLR
UUU
LLDDRR
0 0

0 3 0 -2

</p>