N = int(input()) S = [[] for _ in range(N + 1)] # S[i]:= iを覚えていると思えられる技のリスト L = [0] * (N + 1) # L[i]:= 技iを覚えるのに必要なレベル L[1] = 1 L1 = [-1] * (N + 1) L1[1] = 1 for i in range(2, N + 1): l, s = map(int, input().split()) S[s].append(i) L[i] = l q = [1] while q: x = q.pop(-1) for y in S[x]: L1[y] = max(L1[x], L[y]) q.append(y) L2 = L1[:] L2.sort() from bisect import * x = bisect_left(L2, 0) L2 = L2[x:] # print(L) # print(L2) Q = int(input()) for _ in range(Q): t, x = map(int, input().split()) if t == 1: print(bisect_right(L2, x)) else: print(L1[x])