// #include #include using namespace std; using namespace atcoder; using ll = long long; #define rep(i, n) for (int i=0; i<(int)(n); ++(i)) #define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i)) #define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i)) #define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i)) #define all(x) (x).begin(), (x).end() const string tar = "BGR"; int main() { int t0; cin >> t0; rep(i0, t0) { int n; cin >> n; vector> cd(3, vector(n)); rep(i, n) { char cti; int ci, di; cin >> cti >> di; ci = tar.find(cti); di--; cd[ci][di] = true; } vector ids; rep(i, 3) if (count(all(cd[i]), true) > 0) ids.push_back(i); if ((int)(ids.size()) == 1) cout << "YES" << endl; else if ((int)(ids.size()) == 2) { bool ok = false; rep(i, n) if (cd[ids[0]][i] && cd[ids[1]][i]) { ok = true; break; } if (ok) cout << "YES" << endl; else cout << "NO" << endl; } else { vector> cd2; rep(i1, 3) { rep3(j1, i1+1, 3) { vector tcd(n); rep(i, n) if (cd[i1][i] && cd[j1][i]) tcd[i] = true; cd2.push_back(tcd); } } bool ok = false; rep(i1, 3) if (count(all(cd2[i1]), true) >= 1) { rep3(j1, i1+1, 3) if (count(all(cd2[j1]), true) >= 1) { int bcnt = 0; rep(i, n) if (cd2[i1][i] || cd2[j1][i]) ++bcnt; if (bcnt >= 2) { ok = true; break; } } if (ok) break; } if (ok) cout << "YES" << endl; else cout << "NO" << endl; } } return 0; }