#include using namespace std; const string colors = "RGBY"; void test(int t) { int N; cin >> N; vector< int > C(N), D(N); for (int i = 0; i < N; i++) { char c; cin >> c >> D[i]; C[i] = colors.find(c); } vector< int > cnt(1 << 4); { map< int, int > mp; for (int i = 0; i < N; i++) { mp[D[i]] |= 1 << C[i]; } for (auto &p: mp) { cnt[p.second]++; } } for(int i = 0; i < 4; i++) { cnt[1 << i] = min(cnt[1 << i], 1); } auto get_only = [&](int bit) { if(bit == 1 or bit == 2 or bit == 4 or bit == 8) return bit; return 0; }; auto end = [&](int only)-> bool { for(int i = 0; i < 4; i++) { if((~only >> i) & 1) { for(int j = 0; j < (1 << 4); j++) { if(cnt[j] > 0 and ((j >> i) & 1)) { return false; } } } } return true; }; auto dfs = [&](auto &dfs, int depth, int now, int last, int only) -> bool { if(last) cnt[last]++; if(end(only)) return true; if(last) cnt[last]--; if(depth >= 11) return false; for(int i = 0; i < 4; i++) { if((last >> i) & 1) { if(dfs(dfs, depth + 1, i, last ^ (1 << i), only)) { return true; } } } if(last) cnt[last]++; for(int i = 1; i < (1 << 4); i++) { if(cnt[i] > 0 and ((i >> now) & 1)) { cnt[i]--; if(dfs(dfs, depth + 1, now, i ^ (1 << now), only | get_only(i))) { return true; } cnt[i]++; } } if(last) cnt[last]--; return false; }; for(int i = 1; i < (1 << 4); i++) { if(cnt[i] > 0) { cnt[i]--; for(int j = 0; j < 4; j++) { if((i >> j) & 1) { if (dfs(dfs, 1, j, i ^ (1 << j), get_only(i))) { cout << "YES" << endl; return; } } } cnt[i]++; } } cout << "NO" << endl; } int main() { int T; cin >> T; for(int t = 1; t <= T; t++) { test(t); } }