#include <bits/stdc++.h> #define int long long #define ll long long #define sz(x) (int)(x).size() #define all(x) begin(x),end(x) #define rep(i,a,b) for (int i=(a);i<(b);i++) using namespace std; string to_string (string s) {return s; } template <typename T> string to_string(T v) { bool first = true; string res = "["; for (const auto & x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "]"; return res; } void dbg_out() { cout << endl;} template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif void solve() { int N; cin >> N; string s; cin >> s; int nbW = 0; vector <pair<int,int> > valR; int nbR = 0; for (int i = 0 ; i < N ; i++) { if (s[i] == 'W') nbW++; else { nbR++; valR.push_back({nbR + (nbW+1)/2, nbR + nbW}); } } if (nbW % 2) { cout<<"NO"<<endl; return; } vector <pair<int,int> > valW; int nbR2 = 0; int nbW2 = 0; for (int i = 0 ; i < N ; i++) { if (s[i + N] == 'R') nbR2++; else { nbW2++; valW.push_back({nbW2 + nbW/2, nbW2 + nbW/2 + nbR2}); } } if (sz(valW) != sz(valR)) { cout<<"NO"<<endl; return; } for (int i = 0 ; i < sz(valR) ; i++) { dbg(valR[i].first,valR[i].second,valW[i].first,valW[i].second); if (valR[i].second < valW[i].first || valR[i].first > valW[i].second) { cout<<"NO"<<endl; return; } } cout<<"YES"<<endl; } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; for (int i = 0 ; i < N ; i++) { solve(); } }