#include using namespace std; using ll = long long; int main() { int n; cin >> n; vector> g(n); vector levels(n); for (int i = 1; i < n; i++) { int l, a; cin >> l >> a; --a; levels[i] = l; g[a].push_back(i); } vector type2(n, -1); queue que; que.push(0); type2[0] = 0; while (!que.empty()) { auto cur = que.front(); que.pop(); for (auto to : g[cur]) { if (auto greaterLevel = max(levels[to], levels[cur]); type2[to] < greaterLevel) { type2[to] = greaterLevel; } que.push(to); } } auto type1 = type2; int exclude = 0; for (int i = 0; i < n; i++) { if (type1[i] == -1) { exclude++; } } sort(type1.begin(), type1.end()); int q; cin >> q; while (q--) { int type, x; cin >> type >> x; if (type == 1) { cout << (upper_bound(type1.begin(), type1.end(), x) - type1.begin()) - exclude << endl; } else { cout << type2[x - 1] << endl; } } }