#include<iostream>
#include<fstream>
using namespace std;
long unsigned H[11][1000000];
int op3(int val)
{int rest=val%10;
int i=0;
while(H[rest][i]!=0)
{if(H[rest][i]==val)
return i;
i++;
}
return -1;
}
int op1(int val)
{int rest=val%10;
int i=op3(val);
if(i!=-1)return 0;
int j=0;
while(H[rest][j]!=0)
j++;
H[rest][j]=val;
}
int op2(int val)
{int rest=val%10;
int i=op3(val);
if(i==-1)return 0;
int j=i+1;
while(H[rest][j+1]!=0)
j++;
H[rest][i]=H[rest][j];
}
int main()
{int i,n,op,x;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f>>n;
for(i=1;i<=n;i++)
{f>>op;
f>>x;
if(op==1)
op1(x);
if(op==2)
op2(x);
if(op==3)
if(op3(x)!=-1)
g<<1<<endl;
else
g<<0<<endl;
}
return 0;
}