#include <bits/stdc++.h> using namespace std; #define all(x) ::begin(x), ::end(x) #define tsolve int t; cin >> t; while (t--) solve #define sz(x) (int)::size(x) using ll = long long; using ld = long double; ll n; string s; bool test() { ll w = 0; bool r = false; for (ll i = 0; i < n; ++i) { if (s[i] == 'W') { if (r) { --w; if (w < 0) { return false; } } else { ++w; } } else r = true; } return w % 2 == 0; } void solve() { cin >> n; cin >> s; if (!test()) { cout << "NO\n"; return; } reverse(all(s)); for (char& c : s) { if (c == 'W') c = 'R'; else c = 'W'; } if (!test()) { cout << "NO\n"; return; } cout << "YES\n"; } int main() { cout.tie(0)->sync_with_stdio(false); cout << setprecision(16); tsolve(); }