#include #include #include #include #include using namespace std; constexpr int R = 0, G = 1, B = 2; bool solve(int n, const vector> &a) { int col[3] = {0, 0, 0}; for (int c = 0; c < 3; ++c) for (int i = 0; i < n; ++i) if (a[i][c]) ++col[c]; set s[2][3]; for (int c1 = 0; c1 < 3; ++c1) { for (int c2 = c1 + 1; c2 < 3; ++c2) { for (int i = 0; i < n; ++i) if (a[i][c1] && a[i][c2]) s[c1][c2].insert(i); } } for (int i = 0; i < n; ++i) cerr << int(a[i][0]) << int(a[i][1]) << int(a[i][2]) << '\n'; if (const int ex_sum = int(col[0] > 0) + int(col[1] > 0) + int(col[2] > 0); ex_sum == 1) return true; else if (ex_sum == 2) return !s[0][1].empty() || !s[0][2].empty() || !s[1][2].empty(); else { if (int(s[0][1].empty()) + int(s[0][2].empty()) + int(s[1][2].empty()) >= 2) return false; if (s[0][1].size() > 1 || s[0][2].size() > 1 || s[1][2].size() > 1) return true; set t; if (!s[0][1].empty()) t.insert(*s[0][1].begin()); if (!s[0][2].empty()) t.insert(*s[0][2].begin()); if (!s[1][2].empty()) t.insert(*s[1][2].begin()); if (t.size() > 1) return true; return int(col[0] > 1) + int(col[1] > 1) + int(col[2] > 1) < 3; } } int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector> a(n); for (int i = 0; i < n; ++i) { char c; int d; cin >> c >> d; a[d - 1][c == 'R' ? R : c == 'G' ? G : B] = true; } cout << (solve(n, a) ? "YES\n" : "NO\n"); } }