#include using namespace std; #define REP(i,n) for(int i=0;i P; int main(void){ int i; cin.tie(0); ios_base::sync_with_stdio(false); int T; cin >> T; REP(tc,T){ int N; cin >> N; vector b,g,r; for(i=1;i<=N;i++){ char c; int x; cin >> c >> x; if(c=='B') b.push_back(x); if(c=='G') g.push_back(x); if(c=='R') r.push_back(x); } int bb=b.size(),gg=g.size(),rr=r.size(); bool f=false; if(bb==0 && gg==0) f=true; else if(gg==0 && rr==0) f=true; else if(rr==0 && bb==0) f=true; if(f){ cout << "YES" << endl; continue; } sort(b.begin(),b.end()); sort(g.begin(),g.end()); sort(r.begin(),r.end()); if(bb==0 && gg!=0 && rr!=0){ REP(i,gg){ if(binary_search(r.begin(),r.end(),g[i])){ f=true; break; } } if(f) cout << "YES" << endl; else cout << "NO" << endl; continue; } if(bb!=0 && gg==0 && rr!=0){ REP(i,bb){ if(binary_search(r.begin(),r.end(),b[i])){ f=true; break; } } if(f) cout << "YES" << endl; else cout << "NO" << endl; continue; } if(bb!=0 && gg!=0 && rr==0){ REP(i,bb){ if(binary_search(g.begin(),g.end(),b[i])){ f=true; break; } } if(f) cout << "YES" << endl; else cout << "NO" << endl; continue; } if(bb==1){ if(binary_search(g.begin(),g.end(),b[0]) && binary_search(r.begin(),r.end(),b[0])){ f=true; break; } if(f) cout << "YES" << endl; else cout << "NO" << endl; continue; } if(gg==1){ if(binary_search(b.begin(),b.end(),g[0]) && binary_search(r.begin(),r.end(),g[0])){ f=true; break; } if(f) cout << "YES" << endl; else cout << "NO" << endl; continue; } if(rr==1){ if(binary_search(b.begin(),b.end(),r[0]) && binary_search(g.begin(),g.end(),r[0])){ f=true; break; } if(f) cout << "YES" << endl; else cout << "NO" << endl; continue; } int p=-1; REP(i,bb){ if(binary_search(g.begin(),g.end(),b[i])){ p=b[i]; break; } } REP(i,bb){ if(b[i]==p) continue; if(binary_search(r.begin(),r.end(),b[i])){ if(p!=-1){ f=true; break; } } } if(f){ cout << "YES" << endl; continue; } p=-1; REP(i,gg){ if(binary_search(b.begin(),b.end(),g[i])){ p=g[i]; break; } } REP(i,gg){ if(g[i]==p) continue; if(binary_search(r.begin(),r.end(),g[i])){ if(p!=-1){ f=true; break; } } } if(f){ cout << "YES" << endl; continue; } p=-1; REP(i,rr){ if(binary_search(b.begin(),b.end(),r[i])){ p=r[i]; break; } } REP(i,rr){ if(r[i]==p) continue; if(binary_search(g.begin(),g.end(),r[i])){ if(p!=-1){ f=true; break; } } } if(f){ cout << "YES" << endl; continue; } cout << "NO" << endl; } return 0; }