import bisect N = int(input()) needLV = [-1 for i in range(0,N+1)] needLV[1] = 0 data = {} LV = [0,0] for i in range(1,N+1): data[i] = [] for i in range(N-1): L,A = map(int,input().split()) data[A].append(i+2) LV.append(L) #print(data) nex = [1] visited = [0 for i in range(0,N+1)] while nex != []: nex2 = [] for i in nex: visited[i] = 1 for j in data[i]: if visited[j] == 0: needLV[j] = max(LV[i],LV[j],needLV[i]) nex2.append(j) nex = nex2.copy() Q = int(input()) bisect_lis = [] for i in range(0,len(needLV)): if needLV[i] == -1: bisect_lis.append(10**10) else: bisect_lis.append(needLV[i]) bisect_lis = sorted(bisect_lis) for i in range(Q): num,sub = map(int,input().split()) if num == 1: print(bisect.bisect_right(bisect_lis,sub)) else: print(needLV[sub])