The Ultimate Wine Tasting Event
시간 제한2초메모리 제한2048 MB
W가 n개, R이 n개인 문자열이 주어질 때, 두 부분집합을 골라 서로 대응하는 위치를 교환해 앞 n자리를 모두 W로 만들 수 있는지 판정한다.
문제
Rumors of the excellence of Gabriella’s wine tasting events have toured the world and made it to the headlines of prestigious wine magazines. Now, she has been asked to organize an event at the EUC 2025!
This time she selected bottles of wine, of which exactly are of white wine, and exactly of red wine. She arranged them in a line as usual, in a predetermined order described by a string of length : for , the -th bottle from the left is white wine if W and red wine if R.
To spice things up for the attendees (which include EUC contestants), Gabriella came up with the following wine-themed problem:
Consider a way of dividing the bottles into two disjoint subsets, each containing bottles. Then, for every , swap the -th bottle in the first subset (from the left) and the -th bottle of the second subset (also from the left). Is it possible to choose the subsets so that, after this operation is done exactly once, the white wines occupy the first positions?
입력
The first line contains an integer () — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains an integer () — where is the total number of bottles.
The second line of each test case contains a string of length , describing the bottle arrangement — the -th character of () is W for a white wine and R for a red wine.
It is guaranteed that contains exactly W’s and R’s.
출력
For each test case, print YES if it is possible to divide the bottles as explained in the statement. Otherwise, print NO.