#C11350. Final Coordinates After Movements

    ID: 40657 Type: Default 1000ms 256MiB

Final Coordinates After Movements

Final Coordinates After Movements

You are given a sequence of movements represented by the characters U, D, L, and R, which denote moving up, down, left, and right respectively.

You are also given an integer S indicating the total number of steps to be taken. The movement sequence is repeated as many times as necessary until exactly S moves are performed.

Assume that you start at the point (0, 0) on the Cartesian plane. Your task is to determine the final coordinates (x, y) after performing all S moves.

The overall change after one full iteration of the sequence can be computed as follows: $$ \Delta x = \sum_{i=1}^{n} d_{x_i},\quad \Delta y = \sum_{i=1}^{n} d_{y_i}, $$ where n is the length of the sequence and each movement contributes a change dx and dy according to its direction. If the sequence is repeated full times, with a remainder of rem moves, then the final coordinates are given by: $$ x = full \times \Delta x + \sum_{i=1}^{rem} d_{x_i}, \quad y = full \times \Delta y + \sum_{i=1}^{rem} d_{y_i}. $$

inputFormat

The first line of input contains an integer T representing the number of test cases.

Each of the following T lines contains a test case with a movement sequence (a string consisting of the characters 'U', 'D', 'L', 'R') followed by an integer S, separated by a space.

outputFormat

For each test case, output a single line containing two space-separated integers representing the final coordinates x and y.

## sample
3
UDLR 4
UD 5
L 3
0 0

0 1 -3 0

</p>