from bisect import bisect_right n=int(input()) assert 2<=n<=2*10^5 lp=[list(map(int,input().split())) for _ in range(n-1)] cil=[[]for _ in range(n)] for i in range(1,n): l,p=lp[i-1] assert 1<=l<=10**9 assert 1<=p<=n and p!=i+1 cil[p-1].append((i,l)) level=[10**10]*n level[0]=0 sta=[0] for node in sta: for mode,l in cil[node]: level[mode]=max(level[node],l) sta.append(mode) level_s=sorted(level) q=int(input()) assert 1<=q<=2*10**5 for _ in range(q): q,xy=map(int, input().split()) assert q==1 or q==2 if q==1: assert 1<=xy<=10**9 print(bisect_right(level_s,xy)) else: assert 2<=xy<=n if level[xy-1]==10**10:print(-1) else:print(level[xy-1])