#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cstring>
#include <string>
#include <fstream>
using namespace std;
const int MAXSTEP = 20;
const int prime = 402653189;
const int sz = 1000000;
#define F1 (h(a1, b1, prime, x, sz))
#define F2 (h(a2, b2, prime, x, sz))
inline int h(int a, int b, int prime, int val, int sz) {
return ( (1LL * a * val + b) % prime ) % sz;
}
inline void createFunctions(int &a1, int &a2, int &b1, int &b2) {
a1 = rand() % sz;
a2 = rand() % sz;
b1 = rand() % sz;
b2 = rand() % sz;
}
inline void createTable(int *&h1, int *&h2, char *&v1, char *&v2, int n) {
h1 = new int[n];
h2 = new int[n];
v1 = new char[n];
v2 = new char[n];
memset(v1, 0, sizeof(v1));
memset(v2, 0, sizeof(v2));
memset(h1, 0, sizeof(h1));
memset(h2, 0, sizeof(h2));
}
inline void insert( int *&h1, int *&h2, char *&v1, char *&v2,
int a1, int b1, int a2, int b2, int x) {
int steps = 0;
while(steps < MAXSTEP) {
int y;
steps += 2;
if( v1[F1] == 0) {
h1[F1] = x ;
v1[F1] = 1;
return ;
}
y = h1[F1] ;
h1[F1] = x;
if(v2[F2] == 0) {
h2[F2] = y;
v2[F2] = 1;
return ;
}
x = h2[F2] ;
h2[F2] = y ;
}
}
inline bool find( int *&h1, int *&h2, char *&v1, char *&v2,
int a1, int b1, int a2, int b2, int x) {
return ( (v1[F1] == 1 && h1[F1] == x) || (v2[F2] == 1 && h2[F2] == x) ) ;
}
inline void sterge( int *&h1, int *&h2, char *&v1, char *&v2,
int a1, int b1, int a2, int b2, int x) {
if( h1[F1] == x && v1[F1] == 1) {
h1[F1] = 0;
v1[F1] = 0;
}
if(h2[F2] == x && v2[F2] == 1) {
h2[F2] = 0;
v2[F2] = 0;
}
}
void deleteTable(int *&h1, int *&h2, char *&v1, char *&v2) {
delete[] h1 ; delete[] h2 ; delete[] v1 ; delete[] v2 ;
}
int main() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
srand(time(NULL));
int a1, b1, a2, b2;
int *h1, *h2;
char *v1, *v2;
int Q, op, x;
createFunctions(a1, a2, b1, b2);
createTable(h1, h2, v1, v2, sz);
// cout << a1 << " " << a2 << " " << b1 << " " << b2 << "\n";
for( fin >> Q; Q--; ) {
fin >> op >> x;
if(op == 1) {
insert(h1, h2, v1, v2, a1, b1, a2, b2, x);
}
if(op == 2) {
if( int(find(h1, h2, v1, v2,
a1, b1, a2, b2, x))) {
sterge(h1, h2, v1, v2,
a1, b1, a2, b2, x);
}
}
if(op == 3) {
fout << int(find(h1, h2, v1, v2, a1, b1, a2, b2, x)) << "\n";
}
}
deleteTable(h1, h2, v1, v2);
return 0;
}