n = int(input()) l = [input().split() for i in range(n)] s = [[] for _ in range(20)] for i in l: if i[0] == "0": s[int(i[1])-1] = i[2:] elif i[0] == "1": for j in range(20): if i[1] in s[j]: print(j+1) s[j].remove(i[1]) break else: print(-1) else: s[int(i[1])-1] = []