def scc(N,edges):
    M=len(edges)
    start=[0]*(N+1)
    elist=[0]*M
    for e in edges:
        start[e[0]+1]+=1
    for i in range(1,N+1):
        start[i]+=start[i-1]
    counter=start[:]
    for e in edges:
        elist[counter[e[0]]]=e[1]
        counter[e[0]]+=1
    visited=[]
    low=[0]*N
    Ord=[-1]*N
    ids=[0]*N
    NG=[0,0]
    def dfs(v):
        stack=[(v,-1,0),(v,-1,1)]
        while stack:
            v,bef,t=stack.pop()
            if t:
                if bef!=-1 and Ord[v]!=-1:
                    low[bef]=min(low[bef],Ord[v])
                    stack.pop()
                    continue
                low[v]=NG[0]
                Ord[v]=NG[0]
                NG[0]+=1
                visited.append(v)
                for i in range(start[v],start[v+1]):
                    to=elist[i]
                    if Ord[to]==-1:
                        stack.append((to,v,0))
                        stack.append((to,v,1))
                    else:
                        low[v]=min(low[v],Ord[to])
            else:
                if low[v]==Ord[v]:
                    while(True):
                        u=visited.pop()
                        Ord[u]=N
                        ids[u]=NG[1]
                        if u==v:
                            break
                    NG[1]+=1
                low[bef]=min(low[bef],low[v])
    for i in range(N):
        if Ord[i]==-1:
            dfs(i)
    for i in range(N):
        ids[i]=NG[1]-1-ids[i]
    group_num=NG[1]
    counts=[0]*group_num
    for x in ids:
        counts[x]+=1
    groups=[[] for i in range(group_num)]
    for i in range(N):
        groups[ids[i]].append(i)
    return groups

N=int(input())
G=[]
X=[(0,-1)]
INF=10**15
for i in range(1,N):
    l,a=map(int,input().split())
    X.append((l,a-1))
    G.append((i,a-1))
S=scc(N,G)
for i in range(len(S)):
    if len(S[i])>1:
        for j in range(len(S[i])):
            X[S[i][j]]=(INF,0)
import sys
sys.setrecursionlimit(10**6)
L=[-1]*N
G2=[[] for i in range(N)]
for i in range(1,N):
    G2[i].append(X[i][1])
def dfs(n):
    if L[n]>=0:
        return L[n]
    L[n]=X[n][0]
    for i in range(len(G2[n])):
        L[n]=max(L[n],dfs(G2[n][i]))
    return L[n]

for i in range(N):
    dfs(i)
C=sorted(L)
from bisect import *
Q=int(input())
for i in range(Q):
    t,x=map(int,input().split())
    if t==1:
        print(bisect_right(C,x))
    else:
        if L[x-1]>=INF:
            print(-1)
        else:
            print(L[x-1])