题目描述
The Professor is facing the North. Tokyo is in trouble, and she is facing the South. Professor being her guardian angel wants to help her.
So, The Professor will follow some instructions, given as a string S of length N, and will turn either left or right according to these instructions. He can save Tokyo only if after following a [substring] of instructions he will face in the same direction that Tokyo is facing.
Will the Professor be able to save Tokyo?
------ Input Format ------
- The first line contains an integer T denoting the number of test cases. The T test cases then follow.
- The first line of each test case contains N.
- The second line contains a string that contains only 'L' and 'R', where 'L' represents left and 'R' represents right.
------ Output Format ------
For each test case, output "YES" if the Professor will be able to save Tokyo and "NO" otherwise.
Output is case insensitive, which means that "yes", "Yes", "YEs", "no", "nO" - all such strings will be acceptable.
------ Constraints ------
$1 ≤ T ≤ 100$
$2 ≤ N ≤ 10^{5}$
- The string $S$ consists of uppercase characters 'L' and 'R' only.
- The sum of $N$ over all test cases does not exceed $10^{6}$.
----- Sample Input 1 ------
3
12
LRLRRRLRLLLL
2
LR
4
LRRL
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case $1$: Professor can select the substring "RLRLLL", after following the instructions given by it, Professor will face South.
Test case $2$: No matter which substring Professor selects, the final direction of Professor will never be that in which Tokyo is facing.
输入格式
见题面
输出格式
见题面