#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; REP(i,N){ 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); } sort(b.begin(),b.end()); sort(g.begin(),g.end()); sort(r.begin(),r.end()); b.erase(unique(b.begin(),b.end()),b.end()); g.erase(unique(g.begin(),g.end()),g.end()); r.erase(unique(r.begin(),r.end()),r.end()); int n=b.size(),m=g.size(),p=r.size(); if((n==0 && m==0 && p!=0) || (m==0 && p==0 && n!=0) || (p==0 && n==0 && m!=0)){ cout << "YES" << endl; return 0; } int d=0,e=0,f=0; vector v; REP(i,n) v.push_back(b[i]); REP(i,m) v.push_back(g[i]); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); int z=v.size(); if(n+m>z) d=1; v.clear(); REP(i,m) v.push_back(g[i]); REP(i,p) v.push_back(r[i]); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); z=v.size(); if(m+p>z) e=1; v.clear(); REP(i,p) v.push_back(r[i]); REP(i,n) v.push_back(b[i]); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); z=v.size(); if(p+n>z) f=1; if((n!=0 && m!=0 && p==0)){ if(d==1) cout << "YES" << endl; else cout << "NO" << endl; return 0; } if((m!=0 && p!=0 && n==0)){ if(e==1) cout << "YES" << endl; else cout << "NO" << endl; return 0; } if((p!=0 && n!=0 && m==0)){ if(f==1) cout << "YES" << endl; else cout << "NO" << endl; return 0; } if(d+e+f==3) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }