import bisect from collections import deque n = int(input()) e = [[] for _ in range(n)] tmp = [1] for i in range(1, n): li, ai = map(int, input().split()) tmp.append(li) e[ai-1].append(i) inf = 1 << 30 l = [inf] * n l[0] = 1 d = deque([0]) while d: u = d.popleft() for v in e[u]: l[v] = max(tmp[v], l[u]) d.append(v) sl = sorted(l) for _ in range(int(input())): t, x = list(map(int, input().split())) if t == 1: print(bisect.bisect_right(sl, x)) else: print(l[x-1] if l[x-1] < inf else -1)