#include using namespace std; vector l; vector> G; vector ans1; void dfs(int curr, int prev){ for(auto x : G[curr]){ if(x == prev){ continue; } ans1[x] = max(ans1[curr], l[x]); dfs(x, curr); } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; G.resize(n); l.resize(n); ans1.assign(n, -1); for(int i = 1; i < n; i++){ int a; cin >> l[i] >> a; a--; G[i].push_back(a); G[a].push_back(i); } ans1[0] = 1; dfs(0, -1); vector ans2; for(int i = 0; i < n; i++){ if(ans1[i] != -1){ ans2.emplace_back(ans1[i]); } } sort(ans2.begin(), ans2.end()); int q; cin >> q; while(q--){ int t; cin >> t; if(t == 1){ int x; cin >> x; auto iter = upper_bound(ans2.begin(), ans2.end(), x); int k = iter - ans2.begin(); cout << k << endl; }else{ int y; cin >> y; y--; cout << ans1[y] << endl; } } }