Under construction

Still being built. Things may change

Driving the Rover

Time limit1sMemory limit128 MB

Summary
Simulate a rover that takes one command per second, tracking its speed, heading, and position, then report the final integer coordinates.
Level

Easy3 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Driving a rover on Mars from Earth is not easy. Signals take a while to reach the rover, and its feedback is far from instantaneous. The rover is also a delicate and expensive vehicle, so it moves slowly and must be given very precise instructions about which motors to use and when. Here we look at a greatly simplified model of driving a rover.

In this model the rover accepts the eight commands FORWARD, BACKWARD, FASTER, SLOWER, STOP, RIGHT, LEFT, and NOOP, which work as follows:

  • FORWARD: the rover starts rolling forward at a speed of 1 cm/s1\text{ cm/s}.
  • BACKWARD: the rover starts rolling backward at a speed of 1 cm/s1\text{ cm/s}.
  • FASTER: if the rover is already rolling forward, its speed increases by 1 cm/s1\text{ cm/s}, but never above 5 cm/s5\text{ cm/s}.
  • SLOWER: if the rover is rolling forward, its speed decreases by 1 cm/s1\text{ cm/s} (if this brings the speed to 00, the rover stops).
  • STOP: the rover stops moving.
  • RIGHT: the rover turns 9090 degrees to the right.
  • LEFT: the rover turns 9090 degrees to the left.
  • NOOP: nothing changes.

The commands FORWARD, BACKWARD, RIGHT, and LEFT take effect only if the rover is stopped at that moment; if it is already moving, the command is ignored. Likewise, FASTER and SLOWER take effect only if the rover is rolling forward; otherwise they are ignored.

Each command corresponds to one second of driving: during that second the rover first processes the command and then moves for one second at the resulting velocity. You are given a sequence of n≤1000n \le 1000 commands for nn consecutive seconds. The rover starts at the point (0,0)(0, 0) facing up. The xx coordinate increases from left to right and the yy coordinate increases from bottom to top. Determine the rover's final location after the nn seconds.

Input

The first line contains the number KK of data sets. Then follow KK data sets, each of the following form:

The first line of a data set contains the number of commands (and seconds) nn. This is followed by nn lines, each containing one of the eight commands above, written in uppercase.

Output

For each data set, output a line Data Set x:, where xx is the data set's number (starting from 11). On the next line, output the rover's final integer coordinates in the order x y. Print a single blank line between consecutive data sets (and no blank line after the last data set).

Examples3

  1. Example 1

    Input
    1
    6
    FORWARD
    RIGHT
    STOP
    RIGHT
    FORWARD
    FASTER
    
    Expected output
    Data Set 1:
    3 2
    
  2. Example 2

    Input
    1
    3
    NOOP
    NOOP
    NOOP
    
    Expected output
    Data Set 1:
    0 0
    
  3. Example 3

    Input
    2
    6
    FORWARD
    RIGHT
    STOP
    RIGHT
    FORWARD
    FASTER
    1
    NOOP
    
    Expected output
    Data Set 1:
    3 2
    
    Data Set 2:
    0 0