from collections import defaultdict N = int(input()) L = [] A = [] for _ in range(N - 1): l, a = map(int, input().split()) L.append(l) A.append(a) A = [(a, i + 2) for i, a in enumerate(A)] A_dict = defaultdict(list) A_dict[1].append(1) L_dict = defaultdict(lambda: -1) L_dict[1] = 1 for a, i in A: l = L[i - 2] if L_dict[a] == -1: continue if L_dict[a] < l: A_dict[l].append(i) L_dict[i] = l else: A_dict[L_dict[a]].append(i) L_dict[i] = L_dict[a] acc = {} prev = 1 acc[prev] = 1 for i, v in A_dict.items(): if i == prev: continue acc[i] = acc[prev] + len(v) prev = i acc_keys = sorted(acc.keys()) Q = int(input()) for _ in range(Q): query = tuple(map(int, input().split())) if query[0] == 1: x = query[1] ok = -1 ng = len(acc_keys) while ng - ok > 1: mid = (ok + ng) // 2 if acc_keys[mid] <= x: ok = mid else: ng = mid print(acc[acc_keys[ok]]) else: y = query[1] print(L_dict[y])