#include<bits/stdc++.h>
using namespace std;
int main(){
set<int>s[21],t;
int n,x,y,k;
cin>>n;
for(int i=0;i<n;i++){
cin>>k;
if(k==6){
cin>>x;
cout<<s[x].size()<<"\n";
continue;
}cin>>x>>y;
if(k==1)s[x].insert(y);
if(k==2)s[x].erase(y);
if(k==3){
if(x==y){
s[x].clear();
continue;
}for(auto i:s[y])s[x].insert(i);
s[y].clear();
}if(k==4){
if(x==y){
s[x].clear();
continue;
}for(auto i:s[y]){
if(s[x].count(i))t.insert(i);
}s[x]=t;
t.clear();
}if(k==5){
if(s[x].count(y))cout<<"Yes\n";
else cout<<"No\n";
}
}return 0;
}