N = int(input()) G = [[] for _ in range(N + 2)] A, B = [0], [0] stack = [] for i in range(1, N + 1): a, b = map(int, input().split()) A.append(a) B.append(b) if a == 1: G[i + 1].append(i) if b == 1: j = stack.pop() G[i].append(j) elif b == 1: print(i) j = stack.pop() print(j) while len(G[j]): j = G[j].pop() print(j) elif b == 2: stack.append(i) else: print(i) j = i while len(G[j]): j = G[j].pop() print(j)