N = int(input()) people = [[] for i in range(20)] for i in range(N): inp = input().split() if inp[0]=='0': num = int(inp[1])-1 for j in range(2,len(inp)): people[num].append(inp[j]) elif inp[0]=='1': susi = inp[1] for j in range(20): for n, l in enumerate(people[j]): if l==susi: people[j].pop(n) print(j+1) break else: continue break else: print(-1) else: people[int(inp[1])-1] = []