CF1779A.Hall of Fame

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

Hall of Fame

Thalia is a Legendary Grandmaster in chess. She has nn trophies in a line numbered from 11 to nn (from left to right) and a lamp standing next to each of them (the lamps are numbered as the trophies).

A lamp can be directed either to the left or to the right, and it illuminates all trophies in that direction (but not the one it is next to). More formally, Thalia has a string ss consisting only of characters 'L' and 'R' which represents the lamps' current directions. The lamp ii illuminates:

  • trophies 1,2,,i11,2,\ldots, i-1 if sis_i is 'L';
  • trophies i+1,i+2,,ni+1,i+2,\ldots, n if sis_i is 'R'.

She can perform the following operation at most once:

  • Choose an index ii (1i<n1 \leq i \lt n);
  • Swap the lamps ii and i+1i+1 (without changing their directions). That is, swap sis_i with si+1s_{i+1}.

Thalia asked you to illuminate all her trophies (make each trophy illuminated by at least one lamp), or to tell her that it is impossible to do so. If it is possible, you can choose to perform an operation or to do nothing. Notice that lamps cannot change direction, it is only allowed to swap adjacent ones.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t100001 \leq t \leq 10\,000). The description of the test cases follows.

The first line of each test case contains a positive integer nn (2n1000002 \leq n \leq 100\,000)  — the number of trophies.

The second line of each test case contains a string ss of length nn consisting only of characters 'L' and 'R'  — the ii-th character describes the direction of the ii-th lamp.

It is guaranteed that the sum of nn over all test cases does not exceed 100000100\,000.

Output

For each test case print 1-1 if it is impossible to illuminate all trophies by performing one operation (or doing nothing). Otherwise, print 00 if you choose not to perform the operation (i.e., the trophies are illuminated by the initial positioning of the lamps), or an index ii (1i<n1 \leq i \lt n) if you choose to swap lamps ii and i+1i+1.

If there are multiple answers, print any.

Note

In the first example, it is possible to swap lamps 11 and 22, or do nothing. In any case, the string "LL" is obtained. Not all trophies are illuminated since trophy 22 is not illuminated by any lamp  — lamp 11 illuminates nothing and lamp 22 illuminates only the trophy 11.

In the second example, it is necessary to swap lamps 11 and 22. The string becomes "RL". Trophy 11 is illuminated by lamp 22 and trophy 22 is illuminated by lamp 11, hence it is possible to illuminate all trophies.

In the third example, all trophies are initially illuminated  — hence, not performing any operation is a valid solution.

In the last two examples performing swaps is not necessary as all trophies are illuminated initially. But, the presented solutions are also valid.

Samples

6
2
LL
2
LR
2
RL
2
RR
7
LLRLLLR
7
RRLRRRL
-1
1
0
-1
3
6

在线编程 IDE

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