from collections import defaultdict n = int(input()) li = [[0] * 22 for _ in range(100)] sushi = {} scnt = 0 kyaku = defaultdict(set) for i in range(n): u = input().split() if u[0] == "0": m = defaultdict(int) a, b = map(int, u[1:3]) for s in u[3:]: if s not in sushi: sushi[s] = scnt scnt += 1 m[s] += 1 for k, v in m.items(): li[sushi[k]][a] = v li[sushi[k]][21] += v kyaku[a].add(k) elif u[0] == "1": s = u[1] if s in sushi and li[sushi[s]][21]: for j in range(1, 21): if li[sushi[s]][j]: print(j) li[sushi[s]][j] -= 1 if li[sushi[s]][j] == 0: kyaku[j].remove(s) li[sushi[s]][21] -= 1 break else: print(-1) else: a = int(u[1]) for b in kyaku[a]: li[sushi[b]][21] -= li[sushi[b]][a] li[sushi[b]][a] = 0 del kyaku[a]