#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=20000000000000; ll mod=998244353; int main(){ ll n; cin >> n; vectorl(n),a(n); vector>g(n); l[0]=0; for (ll i = 1; i < n; i++) { cin >> l[i]>> a[i]; a[i]--; g[a[i]].push_back(i); } ll q; cin >> q; queueque; que.push(0); vectormemo(n,0); while (!que.empty()) { ll v=que.front(); que.pop(); memo[v]=1; for (ll i = 0; i < g[v].size(); i++) { if (memo[g[v][i]]==0) { l[g[v][i]]=max(l[g[v][i]],l[v]); que.push(g[v][i]); } } } for (ll i = 0; i < n; i++) { if (memo[i]==0) { l[i]=inf; } } vectorx=l; x.push_back(inf); sort(x.begin(),x.end()); vectorans; for (ll i = 0; i < q; i++) { ll t; cin >> t; if (t==1) { ll xx; cin >> xx; ll v=lower_bound(x.begin(),x.end(),xx+1)-x.begin(); ans.push_back(v); }else{ ll y; cin >> y; if (l[y-1]==inf) { ans.push_back(-1); continue; } ans.push_back(l[y-1]); } } for (ll i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } }