import sys input = sys.stdin.readline from heapq import * from bisect import * N = int(input()) G = [[] for i in range(N)] for i in range(N - 1): L, A = map(int, input().split()) A -= 1 G[A].append((i + 1, L)) H = [(0, 0)] X, Y = [], [-1] * N now = 0 flag = 1 while H: c, u = H[0] if flag: if c <= now: heappop(H) for v, cc in G[u]: heappush(H, (cc, v)) Y[u] = now X.append(now) else: flag = 0 else: now = c flag = 1 Q = int(input()) for _ in range(Q): q, x = map(int, input().split()) if q == 1: print(bisect_right(X, x)) else: print(Y[x - 1])