q = int(input()) s = set() bit = [[0 for _ in range(2)] for _ in range(30)] for _ in range(q): t, *args = list(map(int, input().split())) if t == 1: xi = args[0] if not xi in s: for i in range(30): bit[i][(xi >> i) & 1] += 1 s.add(xi) elif t == 2: xi = args[0] if xi in s: for i in range(30): bit[i][(xi >> i) & 1] -= 1 s.discard(xi) elif t == 3: if len(s) == 0: print("-1") else: ans = 0 for i in range(30): if bit[i][1] > 0 and bit[i][0] == 0: ans |= (1 << i) print(ans)