#include <bits/stdc++.h>
using namespace std;

void solve() {
    int q;
    cin >> q;
    array<int, 30> bit;
    bit.fill(0);
    set<int> s;

    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            cin >> x;
            if (s.find(x) == s.end()) {
                s.insert(x);
                for (int i = 0; i < 30; i++) {
                    if ((x >> i) & 1) {
                        bit[i]++;
                    }
                }
            }
        } else if (t == 2) {
            int x;
            cin >> x;
            if (s.find(x) != s.end()) {
                s.erase(x);
                for (int i = 0; i < 30; i++) {
                    if ((x >> i) & 1) {
                        bit[i]--;
                    }
                }
            }
        } else {
            int ans = 0;
            for (int i = 0; i < 30; i++) {
                if (s.size() == bit[i]) {
                    ans |= (1 << i);
                }
            }
            if (s.size() == 0) {
                cout << -1 << '\n';
            } else {
                cout << ans << '\n';
            }
        }
    }
}

int main() {
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}