#C1399. Ball Passing Game

    ID: 43588 Type: Default 1000ms 256MiB

Ball Passing Game

Ball Passing Game

You are given a circle of n friends numbered from 1 to n, where friend 1 initially holds a ball. The ball is passed according to a sequence of k moves described by a string of characters. Each character in the string is either 'R' or 'L', representing a pass to the right (clockwise) or left (counterclockwise), respectively.

It is guaranteed that the length of the directions string is exactly k. After performing these passes sequentially, determine which friend ends up with the ball.

Note: All passes start from the friend who currently holds the ball. When moving left from friend 1, you wrap around to friend n, and similarly when moving right from friend n, you wrap around to friend 1.

Mathematical Formulation:

If the current friend is denoted by an index i (0-indexed), then passing right updates the index as \( i = (i + 1) \mod n \) and passing left updates the index as \( i = (i - 1 + n) \mod n \). The final answer should be given in 1-indexed format.

inputFormat

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

Each test case is described in a single line containing two integers n and k followed by a string directions. Here, n is the number of friends, k is the number of passes (and the length of the directions string), and directions is a string consisting only of the characters 'R' and 'L'.

outputFormat

For each test case, output a single line containing a single integer — the number of the friend who holds the ball after k passes.

## sample
2
5 3 RLR
6 10 LLLRRRLRLR
2

1

</p>