from collections import defaultdict class UnionFind(): def __init__(self, n): ''' UnionFindクラス。nは要素数を表す。 ''' self.n = n self.parents = [-1] * n def find(self, x): ''' 要素xを含む集合の親を見つける関数。 ''' if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ''' 要素xを含む集合と要素yを含む集合を合体する関数。 基本的には、要素数が多い集合に統合される。 要素数が同じときは要素yを含む集合に統合される。 ''' x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): ''' 要素xを含む集合の要素数を出す関数。 ''' return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) n = int(input()) L = [list(map(int, input().split())) + [i + 2] for i in range(n - 1)] L.sort(key=lambda x: x[0]) C = [set([i]) for i in range(n + 1)] M = [-1 for _ in range(n + 1)] M[1] = 0 q = int(input()) X, Y = [], [] for i in range(q): op, d = map(int, input().split()) if op == 1: X.append((d, i)) else: Y.append((d, i)) X.sort(key=lambda x: x[0]) UF = UnionFind(n + 1) ANS = [-1 for _ in range(q)] xi = 0 if len(X) > 0: cl = X[xi][0] else: cl = 0 for i in range(n - 1): nl, x, y = L[i] root1 = UF.find(1) while xi < len(X) and cl < nl: ANS[X[xi][1]] = len(C[root1]) xi += 1 if xi < len(X): cl = X[xi][0] xroot = UF.find(x) yroot = UF.find(y) UF.union(x, y) root = UF.find(x) if root == xroot: C[xroot] |= C[yroot] else: C[yroot] |= C[xroot] if root1 == xroot: for ym in C[yroot]: M[ym] = nl elif root1 == yroot: for xm in C[xroot]: M[xm] = nl root1 = UF.find(1) while xi < len(X): ANS[X[xi][1]] = len(C[root1]) xi += 1 if xi < len(X): cl = X[xi][0] for yi in range(len(Y)): m, i = Y[yi] ANS[i] = M[m] print(*ANS, sep='\n')