#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 2e5; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int Q; cin >> Q; set st; vector bit_cnt(30, 0); rep(i, Q){ int t; cin >> t; if(t==1){ int x; cin >> x; if(st.find(x)==st.end()){ st.insert(x); for(int j=0; j<30; j++){ bit_cnt[j]+=((x>>j)&1); } } }else if(t==2){ int x; cin >> x; if(st.find(x)!=st.end()){ st.erase(x); for(int j=0; j<30; j++){ bit_cnt[j]-=((x>>j)&1); } } }else{ if((int)st.size()==0){ cout << -1 << "\n"; }else{ int ans = 0; for(int j=0; j<30; j++){ if(bit_cnt[j]==(int)st.size()){ ans += (1<