from collections import Counter N = int(input()) l = [False for _ in range(21)] for _ in range(N): u = list(map(str,input().split())) if len(u) == 2: if u[0] == '1': #データ1の処理 b,count,flg = u[1],-1,True for d in l: count += 1 if not d: continue if b in d: d[b] -= 1 print(count) flg = False if d[b] == 0: del d[b] break if flg: print(-1) else: #データ2の処理 c = int(u[1]) l[c] = False else: #データ0の処理 A,n = dict(Counter(u[3:])),int(u[1]) l[n] = A