import bisect, collections N = int(input()) E = [[] for _ in range(N)] TEMP = [1] for i in range(1, N): Li, Ai = map(int, input().split()) TEMP.append(Li) E[Ai - 1].append(i) INFINITY = 1 << 30 L = [INFINITY] * N L[0] = 1 D = collections.deque([0]) while D: U = D.popleft() for V in E[U]: L[V] = max(TEMP[V], L[U]) D.append(V) SL = sorted(L) for _ in range(int(input())): T, X = list(map(int, input().split())) if T == 1: print(bisect.bisect_right(SL, X)) else: print(L[X - 1] if L[X - 1] < INFINITY else -1)