#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; } vector s,t; REP(i,bb) if(binary_search(g.begin(),g.end(),b[i])) s.push_back(b[i]); REP(i,bb) if(binary_search(r.begin(),r.end(),b[i])) t.push_back(b[i]); int n=s.size(),m=t.size(); if(n!=0 && m!=0){ if(bb==1){ if(s[0]==t[0]) f=true; }else{ if(n>=2 && m>=1) f=true; if(n>=1 && m>=2) f=true; if(n==1 && m==1 && s[0]!=t[0]) f=true; } } if(f){ cout << "YES" << endl; continue; } s.clear(); t.clear(); REP(i,gg) if(binary_search(b.begin(),b.end(),g[i])) s.push_back(g[i]); REP(i,gg) if(binary_search(r.begin(),r.end(),g[i])) t.push_back(g[i]); n=s.size(),m=t.size(); if(n!=0 && m!=0){ if(gg==1){ if(s[0]==t[0]) f=true; }else{ if(n>=2 && m>=1) f=true; if(n>=1 && m>=2) f=true; if(n==1 && m==1 && s[0]!=t[0]) f=true; } } if(f){ cout << "YES" << endl; continue; } s.clear(); t.clear(); REP(i,rr) if(binary_search(b.begin(),b.end(),r[i])) s.push_back(r[i]); REP(i,rr) if(binary_search(g.begin(),g.end(),r[i])) t.push_back(r[i]); n=s.size(),m=t.size(); if(n!=0 && m!=0){ if(rr==1){ if(s[0]==t[0]) f=true; }else{ if(n>=2 && m>=1) f=true; if(n>=1 && m>=2) f=true; if(n==1 && m==1 && s[0]!=t[0]) f=true; } } if(f){ cout << "YES" << endl; continue; } cout << "NO" << endl; } return 0; }