#include #include #include #include int main() { int t; std::cin >> t; while (t-- > 0) { int n; std::cin >> n; std::vector> nums(3); std::vector> cols(n); for (int i = 0; i < n; ++i) { char c; int d; std::cin >> c >> d; --d; int col = c == 'R' ? 0 : c == 'G' ? 1 : 2; nums[col].push_back(d); cols[d].push_back(col); } int c = 0; for (int i = 0; i < 3; ++i) { c += nums[i].size() != 0; } if (c == 1) { std::cout << "YES" << '\n'; continue; } if (c == 2) { std::string ans = "NO"; for (int i = 0; i < n; ++i) { if (cols[i].size() >= 2) { ans = "YES"; } } std::cout << ans << '\n'; continue; } int cnt = 0; atcoder::dsu uf(3); for (int i = 0; i < n; ++i) { int siz = cols[i].size(); for (int j = 0; j < siz - 1; ++j) { int c1 = cols[i][j]; int c2 = cols[i][j + 1]; uf.merge(c1, c2); } cnt += siz >= 2; } if (uf.groups().size() >= 2) { std::cout << "NO" << '\n'; continue; } { bool ok = false; for (int i = 0; i < 3; ++i) { if (nums[i].size() == 1) { ok = true; } } if (ok) { std::cout << "YES" << '\n'; continue; } } if (cnt >= 2) { std::cout << "YES" << '\n'; continue; } else { std::cout << "NO" << '\n'; continue; } } }