#include "bits/stdc++.h" using namespace std; void solve() { int n; cin >> n; string s; cin >> s; deque<char> ltrs; int cnt1 = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'W') cnt1++; } if (cnt1 % 2) { cout << "NO\n"; return; } int k = cnt1 / 2; cnt1 = n - cnt1; vector<pair<int, char>> trg1, trg2; for (int i = 0; i < k; ++i) { trg1.push_back({1, 'W'}); trg2.push_back({1, 'W'}); } for (int i = 0; i < cnt1; ++i) { trg1.push_back({1, 'R'}); trg2.push_back({0, 'W'}); } for (int i = 0; i < n-k-cnt1; ++i) { trg1.push_back({0, 'R'}); trg2.push_back({0, 'R'}); } vector<vector<int>> dp(n + 1, vector<int>(n + 1)); dp[0][0] = 1; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { int t = i + j; if (dp[i][j] == 0) continue; //cerr << i << ' ' << j << '\n'; if (t == s.size()) continue; pair<int, char> el = {t < n, s[t]}; //cerr << trg2[j].first << ' ' << trg2[j].second << '\n'; if (i < n) { if (el == trg1[i]) dp[i+1][j] = 1; } if (j < n) { if (el == trg2[j]) dp[i][j + 1] = 1; } } } if (dp[n][n]) cout << "YES\n"; else cout << "NO\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int t; cin >> t; while (t--) solve(); }