#K77527. Robot Movement Simulation

    ID: 34884 Type: Default 1000ms 256MiB

Robot Movement Simulation

Robot Movement Simulation

This problem requires simulating the movement of a robot on a 2D plane based on a series of instructions. The robot starts at the origin \((0,0)\) and moves according to the given instructions. Each instruction consists of a direction and a number of steps. The valid directions are:

  • \(UP\): Increase the y-coordinate by the provided number of steps.
  • \(DOWN\): Decrease the y-coordinate by the provided number of steps.
  • \(LEFT\): Decrease the x-coordinate by the provided number of steps.
  • \(RIGHT\): Increase the x-coordinate by the provided number of steps.

You are given multiple test cases. For each test case, compute the final coordinates \((x, y)\) after processing all the instructions. The input is read from standard input (stdin), and your solution should write the results to standard output (stdout) with each coordinate pair on a new line.

inputFormat

The first line contains a single integer \(T\), the number of test cases.

For each test case:

  • The first line contains an integer \(N\), the number of instructions.
  • The following \(N\) lines each contain a direction (\(UP\), \(DOWN\), \(LEFT\), or \(RIGHT\)) and an integer representing the number of steps, separated by a space.

outputFormat

For each test case, output a single line with two space-separated integers representing the final coordinates \(x\) and \(y\) of the robot.

## sample
3
3
UP 5
LEFT 3
DOWN 2
4
RIGHT 10
UP 2
LEFT 5
DOWN 3
3
UP 1
UP 1
DOWN 1
-3 3

5 -1 0 1

</p>