import java.util.*; import java.io.*; import java.math.*; public class Main{ /* 入出力 */ static BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter output = new PrintWriter(System.out); static Scanner sc = new Scanner(System.in); /* 定数 */ static final int infI = Integer.MAX_VALUE; static final long infL = Long.MAX_VALUE; static final long mod = (long)1e9+7; static String yes = "Yes"; static String no = "No"; public static final int [] y4 = {0,1,0,-1}; public static final int [] x4 = {1,0,-1,0}; /* グローバル変数 */ /* Main */ public static void main(String[] args) throws IOException{ int Q = sc.nextInt(); Set SET = new HashSet<>(); int [] bit = new int[30]; while(Q-->0) { int type = sc.nextInt(); if(type == 1) { long x = sc.nextLong(); if(!SET.contains(x)){ SET.add(x); for(int i=0;i<30;i++) { if(((x>>i)&1) == 1L)bit[i]++; } } } if(type == 2) { long x = sc.nextLong(); if(SET.contains(x)){ SET.remove(x); for(int i=0;i<30;i++) { if(((x>>i)&1) == 1L)bit[i]--; } } } if(type == 3) { long ans = 0; if(SET.size() == 0) ans = -1L; else { for(int i=0;i<30;i++) if(bit[i] == SET.size()) ans += (1<