import heapq import bisect as bs INF = 1 << 60 n = int(input()) g = [[] for _ in range(n)] for i in range(1, n): l, a = map(int, input().split()) a -= 1 g[a].append((i, l)) src = 0 dist = [INF for _ in range(n)] dist[src] = 1 hp = [(1, src)] while len(hp) > 0: cd, cur = heapq.heappop(hp) if cd > dist[cur]: continue for nxt, lv in g[cur]: if dist[nxt] <= max(dist[cur], lv): continue dist[nxt] = max(dist[cur], lv) heapq.heappush(hp, (dist[nxt], nxt)) items = [] for v in range(n): if dist[v] < INF: items.append(dist[v]) items.sort() q = int(input()) for _ in range(q): t, x = map(int, input().split()) if t == 1: i = bs.bisect_right(items, x) print(i) elif t == 2: x -= 1 if dist[x] < INF: print(dist[x]) else: print("-1")