s = [[] for _ in range(21)] n = int(input()) for _ in range(n): l = input().split() if l[0] == '0': s[int(l[1])] = l[3:] elif l[0] == '1': for j in range(1, 21): if l[1] in s[j]: print(j) s[j].remove(l[1]) break else: print(-1) else: s[int(l[1])] = []