A. 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,…,i−11,2,…,i−1 if sisi is 'L';
  • trophies i+1,i+2,…,ni+1,i+2,…,n if sisi is 'R'.

She can perform the following operation at most once:

  • Choose an index ii (1≤i<n1≤i<n);
  • Swap the lamps ii and i+1i+1 (without changing their directions). That is, swap sisi with si+1si+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 (1≤t≤100001≤t≤10000). The description of the test cases follows.

The first line of each test case contains a positive integer nn (2≤n≤1000002≤n≤100000)  — 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 100000100000.

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 (1≤i<n1≤i<n) if you choose to swap lamps ii and i+1i+1.

If there are multiple answers, print any.

Example

input

Copy

6
2
LL
2
LR
2
RL
2
RR
7
LLRLLLR
7
RRLRRRL

output

Copy

-1
1
0
-1
3
6

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.

塔利娅是一位国际象棋的传奇大师。她有n个奖杯,排成一排,编号从1到n(从左到右),每个奖杯旁边都有一盏灯(灯的编号与奖杯的编号一样)。

一盏灯可以指向左边或右边,它照亮那个方向的所有奖杯(但不照亮它旁边的那个)。更正式地说,Thalia有一个仅由字符'L'和'R'组成的字符串s,代表灯的当前方向。灯的i点亮了。

trophies 1,2,...,i-1 如果si是'L'。
如果si是'R',奖杯i+1,i+2,...,n。
她最多可以进行一次以下操作。

选择一个索引i(1≤i<n)。
调换灯i和i+1(不改变其方向)。也就是说,将si与si+1互换。
塔利亚要求你照亮她所有的奖杯(使每个奖杯至少被一盏灯照亮),或者告诉她不可能这样做。如果有可能,你可以选择执行操作或什么都不做。注意,灯不能改变方向,只允许调换相邻的灯。

输入
每个测试包含多个测试案例。第一行包含测试用例的数量t(1≤t≤10000)。测试用例的描述如下。

每个测试用例的第一行包含一个正整数n (2≤n≤100000) - 奖杯的数量。

每个测试案例的第二行包含一个长度为n的字符串s,仅由字符'L'和'R'组成--第i个字符描述第i个灯的方向。

保证所有测试案例的n之和不超过100000。

输出
对于每个测试案例,如果不可能通过执行一个操作(或什么都不做)来照亮所有的奖杯,则打印-1。否则,如果你选择不执行该操作,则打印0(即通过灯的初始位置照亮奖杯),如果你选择调换灯i和i+1,则打印索引i(1≤i<n)。

如果有多个答案,请打印任何一个。

题意:
只要考虑是否存在LR的情况就可以了,是要俩个灯交叉的照亮的话,就能全部照亮。还有就是即使初始情况下面全部照亮了,也可以在不影响照亮的情况下,随便移动相邻的灯,输出的是下标,是下标!下标!

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<map>
#include<cstring>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
ll gcdd(ll a, ll b)
{
	if (b) while ((a %= b) && (b %= a));
	return a + b;
}
int n, m, idx, cnt, flag,s;
int head[350];
int dis[350];
bool book[350];
double v;

struct node
{
	int a, b;
	double w,to,come;
	int ne;
}sta[N];


struct space
{
	double x, y;
}spa[N];


void add(int a, int b, double w1,double w2)
{
	sta[idx].a = a;
	sta[idx].b = b;
	sta[idx].to = w1, sta[idx].come = w2;
	sta[idx].ne = head[a];
	head[a] = idx++;
}


int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n;
		string s;
		cin >> s;
		int ans = -1;
		for (int i = 0;i < n - 1;i++)
		{
			if (s[i] == 'L' && s[i + 1] == 'R')
			{
				ans = i + 1;
			}
			else if(s[i+1] == 'L' && s[i ] == 'R')
			{
				ans = 0;
			}
		}
		cout << ans << endl;
	}
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值