/* 1が三食 R 1 2 G 1 3 B 1 5 */ #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=998244353; const double PI=acos(-1); bool solve(){ int N; cin>>N; //set rst,bst,gst; vector> st(3); int match=0; for(int i=0;i>c>>d; if(c=='R'){ st[0].insert(d); //rst.insert(d); match|=(1<<0); }else if(c=='G'){ st[1].insert(d); // gst.insert(d); match|=(1<<1); }else if(c=='B'){ st[2].insert(d); // bst.insert(d); match|=(1<<2); } } if(__builtin_popcount(match)==1){ //そもそもカードが一種類しかない //必ずtrue return true; }else if(__builtin_popcount(match)==2){ //カードが2種類しかない vector cnt(N+1,0); for(int i=0;i<3;i++){ for(int v:st[i]){ cnt[v]++; if(cnt[v]==2){ //2回出現すればOK return true; } } } return false; } //3色ある場合 vector p={0,1,2}; do{ //st[1]に相当するカード->st[0]に相当するカード->st[2]に相当するカード /* st[1],st[0]に相当するカードがあるならflag1=true カード集合をc1 st[0],st[1]に相当するカードがあるならflag2=true カード集合をc2とする flag1とflag2が両方trueのとき st[0]が1種類しかないならtrue */ bool flag1=false,flag2=false; set c1,c2; for(int v:st[p[0]]){ if(st[p[1]].count(v)){ flag1=true; c1.insert(v); } if(st[p[2]].count(v)){ flag2=true; c2.insert(v); } } if(!flag1 || !flag2) continue; if(c1!=c2){ return true; } if(c1==c2){ if(c1.size()>1) return true; //c1.size()==1 if(st[p[0]].size()==1) return true; } }while(next_permutation(p.begin(),p.end())); return false; } int main(){ int T; cin>>T; for(int t=0;t