#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int N,Q; vector> G[202020]; int main() { cin >> N; for(int i = 2; i <= N; ++i) { int l,a; cin >> l >> a; G[a].push_back({l,i}); } vector xans; vector yans(N+1, -1); priority_queue, vector>, greater>> pq; pq.push({1,1}); yans[1] = 1; int level = 1; while(!pq.empty()) { auto [l,a] = pq.top(); pq.pop(); if(level <= l) level = l; xans.push_back(level); yans[a] = level; for(auto [nl,na] : G[a]) pq.push({nl,na}); } cin >> Q; vector ans; while(Q--) { int t,n; cin >> t >> n; if(t == 1) { int mx = upper_bound(xans.begin(),xans.end(),n)-xans.begin(); ans.push_back(mx); } else { ans.push_back(yans[n]); } } for(int v : ans) cout << v << endl; }