#include #include #include #include #include using std::string; enum Color {B, G, R, Y}; Color colors[] = {B, G, R, Y}; typedef unsigned char Value; typedef std::pair Tile; typedef std::set SortCounter; Color to_col(char c) { switch (c) { case 'b': return B; case 'g': return G; case 'r': return R; case 'y': return Y; default: throw; } } void record(string token, SortCounter &counts) { counts.emplace(Tile(to_col(token.back()), std::stoul(token.substr(0, token.size()-1)))); } bool rummisearch(SortCounter &counts) { for (Color c : colors) { for (Value v = 1; v <= 98; ++v) { if (counts.count(Tile(c, v)) && counts.count(Tile(c, v+1)) && counts.count(Tile(c, v+2))) { return true; } } } for (Value v = 1; v <= 100; ++v) { int i = 0; for (Color c : colors) { if (counts.count(Tile(c, v))) { ++i; } if (i >= 3) return true; } } return false; } int main(int argc, char const *argv[]) { int T; std::cin >> T; for (int i = 0; i < T; ++i) { int M; std::cin >> M; SortCounter counter; for (int j = 0; j < M; j++) { std::string in; std::cin >> in; record(in, counter); } if (rummisearch(counter)) { std::cout << "YES" << std::endl; } else { std::cout << "NO" << std::endl; } } return 0; }