#技の種類数は累積和 from collections import defaultdict from collections import deque from bisect import bisect n = int(input()) L = [-1 for _ in range(n)] L[0] = 1 tree = [[] for _ in range(n)] for i in range(n - 1): l, a = map(int, input().split()) tree[i + 1].append(a - 1) tree[a - 1].append(i + 1) L[i + 1] = l q = deque([(0, 1)]) dic = defaultdict(int) seen = [False for _ in range(n)] seen[0] = True while q: now, lev = q.popleft() if L[now] < lev: L[now] = lev for next in tree[now]: if seen[next]: continue q.append((next, L[now])) seen[next] = True for i in range(n): if not seen[i]: L[i] = -1 for i in L: if i != -1: dic[i] += 1 lis1 = list(dic.keys()) lis2 = [0] + [dic[i] for i in lis1] for i in range(len(lis2) - 1): lis2[i + 1] += lis2[i] q = int(input()) for i in range(q): num, x = map(int, input().split()) if num == 1: wh = bisect(lis1, x) print(lis2[wh]) else: print(L[x - 1])