Thalia is a Legendary Grandmaster in chess. She has $n$ trophies in a line numbered from $1$ to $n$ (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 $s$ consisting only of characters 'L' and 'R' which represents the lamps' current directions. The lamp $i$ illuminates:

trophies $1,2,\ldots, i-1$ if $s_i$ is 'L';

trophies $i+1,i+2,\ldots, n$ if $s_i$ is 'R'.

She can perform the following operation at most once:

Choose an index $i$ ($1 \leq i < n$);

Swap the lamps $i$ and $i+1$ (without changing their directions). That is, swap $s_i$ with $s_{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 $t$ ($1 \leq t \leq 10000$). The description of the test cases follows.

The first line of each test case contains a positive integer $n$ ($2 \leq n \leq 100000$)  — the number of trophies.

The second line of each test case contains a string $s$ of length $n$ consisting only of characters 'L' and 'R'  — the $i$-th character describes the direction of the $i$-th lamp.

It is guaranteed that the sum of $n$ over all test cases does not exceed $100000$.


-----Output-----

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

If there are multiple answers, print any.


-----Examples-----

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


-----Note-----

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

In the second example, it is necessary to swap lamps $1$ and $2$. The string becomes "RL". Trophy $1$ is illuminated by lamp $2$ and trophy $2$ is illuminated by lamp $1$, 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.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

String algorithms

Constructive algorithms


Solutions:
for l in [*open(0)][2::2]:
	print(l.find('LR') + 1 | len({*l}) - 3)


from sys import stdin

def solve():
	n = int(stdin.readline())
	s = stdin.readline().strip()
	if all((c == s[0] for c in s)):
		print(-1)
	else:
		p = s.find('LR')
		print(p + 1)
T = int(stdin.readline())
for t in range(T):
	solve()


for k in [*open(0)][2::2]:
	print(k.find('LR') + 1 | len({*k}) - 3)


t = int(input())
anss = []
for _ in range(t):
	n = int(input())
	s = str(input())
	symsSet = set(list(s))
	if len(symsSet) == 1:
		anss.append(-1)
	else:
		found = False
		for i in range(len(s) - 1):
			if s[i:i + 2] == 'LR':
				anss.append(i + 1)
				found = True
				break
		if not found:
			anss.append(0)
for ans in anss:
	print(ans)


t = int(input())
B = []
for i in range(t):
	n = int(input())
	s = input()
	if n == 2:
		if s[0] == s[1] and s[0] == 'L' or (s[0] == s[1] and s[0] == 'R'):
			B.append(-1)
		elif s[0] == 'L' and s[1] == 'R':
			B.append(1)
		else:
			B.append(0)
	else:
		contl = s.count('L')
		contr = s.count('R')
		if contl == n or contr == n:
			B.append(-1)
		else:
			cont = 0
			for j in range(n - 1):
				if s[j] == 'L' and s[j + 1] == 'R':
					B.append(j + 1)
					cont = cont + 1
					break
			if cont == 0:
				B.append(0)
for i in B:
	print(i)


a = int(input())
t = []
for i in range(a):
	s = int(input())
	str = input()
	t.append(str)

def main(f):
	co = 0
	res = 0
	for i in f:
		if i == 'R':
			co = co + 1
	if co == 0 or co == len(f):
		return -1
	else:
		for i in range(len(f) - 1):
			if f[i] == 'L' and f[i + 1] == 'R':
				res = i + 1
				break
		return res
for i in t:
	print(main(i))


import sys
import os

def solve(string):
	fr = None
	for i in range(len(string)):
		if string[i] == 'R':
			fr = i
	if fr is None:
		print(-1)
		return
	fl = None
	for i in range(len(string) - 1, -1, -1):
		if string[i] == 'L':
			fl = i
	if fl is None:
		print(-1)
		return
	if fr < fl:
		print(0)
		return
	for i in range(len(string) - 1):
		if string[i] == 'L' and string[i + 1] == 'R':
			print(i + 1)
			return
	print(-1)
	return
problems = []
n = int(input())
for i in range(n * 2):
	a = input()
	if a.isalpha():
		problems.append(a)
for problem in problems:
	solve(problem)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	s = input()
	if 'L' * n == s or 'R' * n == s:
		print(-1)
	elif 'LR' in s:
		print(s.find('LR') + 1)
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if len(set(s)) == 1:
		print(-1)
	else:
		print(s.find('LR') + 1)


for i in range(int(input())):
	n = int(input())
	a = input()
	if 'LR' in a:
		print(a.index('LR') + 1)
	elif 'RL' in a:
		print(0)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if 'LR' in s:
		print(s.find('LR') + 1)
	elif 'RL' in s:
		print(0)
	else:
		print('-1')