#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int MAXN = (1 << 18);
const int ALPH = 26;
const int CNTBITS = 31;
const int inf = (int)1e16 + 42;
struct node_trie
{
int cnt;
node_trie *next[ALPH];
node_trie() {cnt = 0; for(int i = 0; i < ALPH; i++) next[i] = NULL;}
};
string to_bin(int x)
{
string add_word = "";
for(int bit = CNTBITS; bit >= 0; bit--)
add_word += (char)(((x >> bit) & 1ll) + '0');
return add_word;
}
struct trie
{
node_trie *root;
string add_word;
trie() {root = new node_trie();}
void add(int p, node_trie* curr)
{
if(p == add_word.size())
{
curr->cnt++;
return;
}
if(curr->next[add_word[p] - '0'] == NULL)
curr->next[add_word[p] - '0'] = new node_trie();
add(p + 1, curr->next[add_word[p] - '0']);
curr->cnt++;
}
void del(int p, node_trie* curr)
{
if(p == add_word.size())
{
if(curr->cnt) curr->cnt--;
return;
}
if(curr->next[add_word[p] - '0'] == NULL) return;
del(p + 1, curr->next[add_word[p] - '0']);
curr->cnt--;
}
int find(int p, node_trie* curr)
{
if(p == add_word.size())
return curr->cnt;
if(curr->next[add_word[p] - '0'] == NULL) return -1;
return find(p + 1, curr->next[add_word[p] - '0']);
}
int opposite(int p, node_trie* curr)
{
if(p == add_word.size())
return 0;
int bit = (add_word[p] - '0') ^ 1;
if(curr->next[bit ^ 1] == NULL || curr->next[bit ^ 1]->cnt == 0)
if(curr->next[bit] != NULL && curr->next[bit]->cnt != 0)
return (1 << (CNTBITS - p)) + opposite(p + 1, curr->next[bit]);
else return inf;
return opposite(p + 1, curr->next[bit ^ 1]);
}
void add(string s)
{
add_word = s;
add(0, root);
}
void del(string s)
{
add_word = s;
del(0, root);
}
int find(string s)
{
add_word = s;
return find(0, root);
}
int minxor(string x)
{
add_word = x;
return opposite(0, root);
}
};
int ans[MAXN];
struct segment_tree
{
trie t;
vector<int> tr[4 * MAXN];
void insert(int qL, int qR, int val, int l, int r, int idx)
{
if(qL <= l && r <= qR)
{
tr[idx].push_back(val);
return;
}
if(qL > r || l > qR)
return;
int mid = (l + r) >> 1;
insert(qL, qR, val, l, mid, 2 * idx + 1);
insert(qL, qR, val, mid + 1, r, 2 * idx + 2);
}
void dfs(int res, int l, int r, int idx)
{
int newres = res;
for(int i = 0; i < tr[idx].size(); i++)
{
newres = min(newres, t.minxor(to_bin(tr[idx][i])));
t.add(to_bin(tr[idx][i]));
}
if(l == r) ans[l] = newres;
int mid = (l + r) >> 1;
if(l != r) dfs(newres, l, mid, 2 * idx + 1);
if(l != r) dfs(newres, mid + 1, r, 2 * idx + 2);
for(int i = 0; i < tr[idx].size(); i++)
t.del(to_bin(tr[idx][i]));
}
};
int m;
map<int, int> last;
bool req[MAXN];
vector<pair<int, pair<int, int> > > q;
void read()
{
cin >> m;
for(int i = 1; i <= m; i++)
{
int type;
cin >> type;
if(type == 1)
{
int val;
cin >> val;
last[val] = i;
}
else if(type == 2)
{
int val;
cin >> val;
q.push_back(make_pair(val, make_pair(last[val], i)));
last[val] = 0;
}
else req[i] = true;
}
}
segment_tree t;
void solve()
{
for(map<int, int>::iterator it = last.begin(); it != last.end(); ++it)
if(it->second != 0)
q.push_back(make_pair(it->first, make_pair(it->second, m)));
for(int i = 0; i < q.size(); i++)
t.insert(q[i].second.first, q[i].second.second, q[i].first, 1, m, 0);
t.dfs(inf, 1, m, 0);
for(int i = 1; i <= m; i++)
if(req[i]) cout << ans[i] << endl;
}
#undef int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgojZGVmaW5lIGludCBsb25nIGxvbmcKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBNQVhOID0gKDEgPDwgMTgpOwpjb25zdCBpbnQgQUxQSCA9IDI2Owpjb25zdCBpbnQgQ05UQklUUyA9IDMxOwpjb25zdCBpbnQgaW5mID0gKGludCkxZTE2ICsgNDI7CgpzdHJ1Y3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