Driving the Rover

No attempts yetTime limit1sMemory limit128 MB

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\text{ cm/s}$.
  • BACKWARD: the rover starts rolling backward at a speed of $1\text{ cm/s}$.
  • FASTER: if the rover is already rolling forward, its speed increases by $1\text{ cm/s}$, but never above $5\text{ cm/s}$.
  • SLOWER: if the rover is rolling forward, its speed decreases by $1\text{ cm/s}$ (if this brings the speed to $0$, the rover stops).
  • STOP: the rover stops moving.
  • RIGHT: the rover turns $90$ degrees to the right.
  • LEFT: the rover turns $90$ 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 \le 1000$ commands for $n$ consecutive seconds. The rover starts at the point $(0, 0)$ facing up. The $x$ coordinate increases from left to right and the $y$ coordinate increases from bottom to top. Determine the rover's final location after the $n$ seconds.

Input

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

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

Output

For each data set, output a line Data Set x:, where $x$ is the data set's number (starting from $1$). 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).