from bisect import bisect_right n = int(input()) la_list = [tuple(map(int, input().split())) for _ in range(n - 1)] q = int(input()) query_list = [tuple(map(int, input().split())) for _ in range(q)] # クエリ2を解くグラフ(森になるはず)を作る g = [[] for _ in range(n + 1)] levels = [-1] * (n + 1) for i, (l, a) in enumerate(la_list): g[a].append((i + 2, l)) levels[1] = 0 # 探索 queue = [] queue.append((1, 0)) while len(queue): p, level_p = queue.pop() for q, level_q in g[p]: new_level = max(level_p, level_q) levels[q] = new_level # クエリ1を解くためにbisectする level_list = list(sorted([x for x in levels if x >= 0])) res_list = [] for query in query_list: if query[0] == 1: res = bisect_right(level_list, query[1]) else: res = levels[query[1]] res_list.append(res) for res in res_list: print(res)