N = int(input()) lsD = [[] for i in range(20)] ans = [] for i in range(N): ls = input().split() if ls[0] == '0': n = int(ls[1])-1 m = int(ls[2]) lsD[n] = ls[3:] elif ls[0] == '1': b = ls[1] f = False for i in range(20): for neta in lsD[i]: if b == neta: lsD[i].remove(b) f = True ans.append(i+1) break if f: break if f == False: ans.append(-1) else: c = int(ls[1])-1 lsD[c] = [] print(*ans,sep='\n')