CF2070B.Robot Program

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Robot Program

There is a robot on the coordinate line. Initially, the robot is located at the point xx (x0x \ne 0). The robot has a sequence of commands of length nn consisting of characters, where L represents a move to the left by one unit (from point pp to point (p1)(p-1)) and R represents a move to the right by one unit (from point pp to point (p+1)(p+1)).

The robot starts executing this sequence of commands (one command per second, in the order they are presented). However, whenever the robot reaches the point 00, the counter of executed commands is reset (i. e. it starts executing the entire sequence of commands from the very beginning). If the robot has completed all commands and is not at 00, it stops.

Your task is to calculate how many times the robot will enter the point 00 during the next kk seconds.

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of a test case contains three integers nn, xx and kk (1n21051 \le n \le 2 \cdot 10^5; nxn-n \le x \le n; nk1018n \le k \le 10^{18}).

The second line of a test case contains a string ss consisting of nn characters L and/or R.

Additional constraint on the input: the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

Output

For each test case, print a single integer — the number of times the robot will enter the point 00 during the next kk seconds.

Note

In the first example, the robot moves as follows: $2 \rightarrow 1 \rightarrow \underline{0} \rightarrow -1 \rightarrow -2 \rightarrow -1$. The robot has completed all instructions from the sequence and is not at 00. So it stops after 55 seconds and the point 00 is entered once.

In the second example, the robot moves as follows: $-1 \rightarrow \underline{0} \rightarrow 1 \rightarrow \underline{0} \rightarrow 1 \rightarrow \underline{0} \rightarrow 1 \rightarrow \underline{0} \rightarrow 1$. The robot worked 88 seconds and the point 00 is entered 44 times.

In the third example, the robot moves as follows: $-2 \rightarrow -3 \rightarrow -2 \rightarrow -1 \rightarrow \underline{0} \rightarrow -1$. The robot worked 55 seconds and the point 00 is entered once.

In the fourth example, the robot moves as follows: $3 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 3 \rightarrow 2$. The robot has completed all instructions from the sequence and is not at 00. So it stops after 55 seconds, without reaching the point 00.

Samples

6
3 2 6
LLR
2 -1 8
RL
4 -2 5
LRRR
5 3 7
LRRLL
1 1 1
L
3 -1 4846549234412827
RLR
1
4
1
0
1
2423274617206414

在线编程 IDE

建议全屏模式获得最佳体验