#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
set<int> se;
multiset<int> ans;
auto ins = [&](int x) {
auto it = se.insert(x).first;
auto la = (it == se.begin() ? prev(se.end()) : prev(it));
auto nx = (next(it) == se.end() ? se.begin() : next(it));
if (se.size() > 1) {
ans.insert(x ^ *la);
ans.insert(x ^ *nx);
}
if (se.size() > 2) {
ans.erase(ans.find(*la ^ *nx));
}
};
auto rem = [&](int x) {
auto it = se.find(x);
auto la = (it == se.begin() ? prev(se.end()) : prev(it));
auto nx = (next(it) == se.end() ? se.begin() : next(it));
ans.insert(*la ^ *nx);
if (se.size() > 2) {
ans.erase(ans.find(x ^ *la));
ans.erase(ans.find(x ^ *nx));
}
se.erase(x);
};
multiset<int> occ;
map<int, int> freq;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x;
cin >> x;
if (freq.count(x)) {
occ.erase(occ.find(freq[x]));
}
freq[x]++;
occ.insert(freq[x]);
if (freq[x] == 1) {
ins(x);
}
} else if (t == 2) {
int x;
cin >> x;
occ.erase(occ.find(freq[x]));
freq[x]--;
occ.insert(freq[x]);
if (freq[x] == 0) {
rem(x);
}
} else {
if (*occ.rbegin() > 1) {
cout << 0 << '\n';
} else {
cout << *ans.begin() << '\n';
}
}
}
return 0;
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojaWZkZWYgTmVybwojaW5jbHVkZSAiRGViLmgiCiNlbHNlCiNkZWZpbmUgZGViKC4uLikKI2VuZGlmCgpzaWduZWQgbWFpbigpewogIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICBjaW4udGllKG51bGxwdHIpOwogIGludCBxOwogIGNpbiA+PiBxOwogIHNldDxpbnQ+IHNlOyAKICBtdWx0aXNldDxpbnQ+IGFuczsgCiAgYXV0byBpbnMgPSBbJl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gIG9jYy5lcmFzZShvY2MuZmluZChmcmVxW3hdKSk7ICAgICAgICAKICAgICAgfQogICAgICBmcmVxW3hdKys7IAogICAgICBvY2MuaW5zZXJ0KGZyZXFbeF0pOyAKICAgICAgaWYgKGZyZXFbeF0gPT0gMSkgewogICAgICAgIGlucyh4KTsgICAgICAgICAKICAgICAgfQogICAgfSBlbHNlIGlmICh0ID09IDIpIHsKICAgICAgaW50IHg7CiAgICAgIGNpbiA+PiB4OyAKICAgICAgb2NjLmVyYXNlKG9jYy5maW5kKGZyZXFbeF0pKTsKICAgICAgZnJlcVt4XS0tOyAKICAgICAgb2NjLmluc2VydChmcmVxW3hdKTsgCiAgICAgIGlmIChmcmVxW3hdID09IDApIHsKICAgICAgICByZW0oeCk7ICAgICAgICAgCiAgICAgIH0KICAgIH0gZWxzZSB7CiAgICAgIGlmICgqb2NjLnJiZWdpbigpID4gMSkgewogICAgICAgIGNvdXQgPDwgMCA8PCAnXG4nOwogICAgICB9IGVsc2UgewogICAgICAgIGNvdXQgPDwgKmFucy5iZWdpbigpIDw8ICdcbic7ICAgICAgICAgCiAgICAgIH0KICAgIH0KICB9CiAgcmV0dXJuIDA7Cn0K