全部WA
#include<bits/stdc++.h>
using namespace std;
set<int> s[15];
int op,n,x,y;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
while(n--){
cin>>op;
set<int>::iterator it;
switch(op){
case 1:
cin>>x>>y;
s[x].insert(y);
break;
case 2:
cin>>x>>y;
if(s[x].count(y)) s[x].erase(y);
break;
case 3:
cin>>x>>y;
s[x].insert(s[y].begin(),s[y].end());
s[y].clear();
break;
case 4:
cin>>x>>y;
for(it=s[x].begin();it!=s[x].end();it++){
if(s[y].count((*it))) s[12].insert((*it));
}
s[x].clear(),s[y].clear();
s[x].insert(s[12].begin(),s[12].end());
s[12].clear();
break;
case 5:
cin>>x>>y;
if(s[x].count(y)) cout<<"Yes\n";
else cout<<"No\n";
break;
case 6:
cin>>x;
cout<<s[x].size()<<endl;
break;
}
}
return 0;
}