#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n; vector> g(n); vector l(n); rep(i,n-1){ int a; cin >> l[i+1] >> a; g[a-1].push_back(i+1); } vector dist(n,INF), r(1,0); dist[0] = 0; priority_queue pq; pq.push({0,0}); while(pq.size()){ int now, d; tie(d,now) = pq.top(); pq.pop(); if(dist[now]!=d) continue; r.push_back(d); for(int x:g[now]){ if(chmin(dist[x], max(dist[now], l[x]))) pq.push({dist[x], x}); } } rep(i,n) if(dist[i]==INF) dist[i] = -1; cin >> q; rep(houren,q){ int t,x; cin >> t >> x; if(t==1){ cout << upper_bound(all(r),x) - r.begin()-1 << '\n'; }else{ cout << dist[x-1] << '\n'; } } return 0; }