#include using namespace std; const string COLORS = "BGR"; int main() { int T; cin >> T; while (T--) { int N; cin >> N; vector< int > C(N), D(N); int type = 0; for (int i = 0; i < N; i++) { char c; cin >> c >> D[i]; --D[i]; C[i] = COLORS.find(c); type |= 1 << C[i]; } type = __builtin_popcount(type); if(type == 1) { cout << "YES" << endl; } else if(type == 2) { sort(D.begin(), D.end()); D.erase(unique(D.begin(), D.end()), D.end()); if(D.size() != N) { cout << "YES" << endl; } else { cout << "NO" << endl; } } else { vector< int > perm{0, 1, 2}; bool yes = false; do { vector< int > bit(N); vector< int > sz(3); for (int i = 0; i < N; i++) { bit[D[i]] |= 1 << perm[C[i]]; sz[perm[C[i]]]++; } { vector< int > dp(4); dp[0] = 1; for(int i = 0; i < N; i++) { vector< int > nxt = dp; for(int j = 0; j < 4; j++) { if ((bit[i] & 0b110) == 0b110) { nxt[j | 1] |= dp[j]; } if ((bit[i] & 0b011) == 0b011) { nxt[j | 2] |= dp[j]; } } dp = nxt; } yes |= dp[3]; } { bool all = false; for(auto& p : bit) all |= p == 0b111; yes |= all and sz[1] == 1; } } while (next_permutation(perm.begin(), perm.end())); if(yes) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } }