from functools import reduce import operator 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: if query[1] in S: S.remove(query[1]) elif query[0] == 3: if not S: print(-1) else: result = reduce(operator.and_, S) print(result)