Q = int(input().strip()) S = set() for _ in range(Q): query = list(map(int, input().strip().split())) if query[0] == 1: S.add(query[1]) elif query[0] == 2: S.discard(query[1]) elif query[0] == 3: if len(S) == 0: print(-1) else: result = list(S)[0] for num in list(S)[1:]: result &= num print(result)