import sys input = sys.stdin.readline from collections import defaultdict from bisect import bisect_left, bisect_right # bisect_left(a, x): a[i] >= xとなるような最小のi. # 昇順ソートされたリストaに昇順を崩さずxを挿入できる位置s(0-index)を返す. # a = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] # s = bisect_left(a,4), s = 2 n = int(input()) la = [list(map(int, input().split())) + [i + 1] for i in range(n - 1)] for v in la: v[1] -= 1 la.sort(key=lambda x: x[0]) d = defaultdict(int) d[0] = 1 stk = defaultdict(list) check = [-1] * n check[0] = 1 for level, a, idx in la: if check[a] != -1: check[idx] = level d[level] += 1 que = [idx] while que: k = que.pop() for x in stk[k]: check[x] = level que.append(x) d[level] += 1 stk[k] = [] else: stk[a].append(idx) d = list(d.items()) d.sort(key=lambda x: x[0]) for i in range(len(d) - 1): d[i + 1] = (d[i + 1][0], d[i][1] + d[i + 1][1]) q = int(input()) res = [0] * q for i in range(q): query, x = map(int, input().split()) if query == 1: k = bisect_left(d, (x, n + 10)) res[i] = d[k - 1][1] else: res[i] = check[x - 1] print(*res, sep="\n")