N = int(input()) L = [0] A = [-1] G = [[] for _ in range(N)] for _ in range(N - 1): l,a = map(int,input().split()) L.append(l) A.append(a - 1) G[a-1].append(_ + 1) Q = int(input()) inf = 10 ** 10 level = [-1] * N level[0] = 0 stack = [0] while stack: now = stack.pop() for v in G[now]: level[v] = max(level[now],L[v]) stack.append(v) u = [] for j in level: if j != -1:u.append(j) u.sort() for _ in range(Q): i,t = map(int,input().split()) x = t y = t if i == 1: end = len(u) start = 0 while end - start > 1: mid = end + start >> 1 if u[mid] <= x: start = mid else: end = mid print(end) else: print(level[y-1])