#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } inline double time() { return static_cast(chrono::duration_cast(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector ok(n,-1); ok[0] = 0; vector>> g(n); for (int i = 1; i < n; ++i) { int l,a; cin >> l >> a; a--; g[a].push_back({i,l}); } { queue q; q.push(0); while (q.size()) { int s = q.front(); q.pop(); for (auto p : g[s]) { ok[p.first] = max(p.second, ok[s]); q.push(p.first); } } } vector v; for (int i = 0; i < n; ++i) { if (ok[i] != -1) { v.push_back(ok[i]); } } sort(v.begin(), v.end()); int q; cin >> q; while (q--) { int t,x; cin >> t >> x; if (t == 1) { cout << lower_bound(v.begin(), v.end(), x+1) - v.begin() << "\n"; } else { cout << ok[x-1] << "\n"; } } }