#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace atcoder; using namespace std; using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template ostream &operator<<(ostream &os,const pair&p){ os< istream &operator>>(istream &is,pair&p){ is>>p.first>>p.second; return is; } template istream &operator>>(istream &is,vector &a){ for(auto &i:a)is>>i; return is; } #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() ll myceil(ll a,ll b){return (a+b-1)/b;} int main(){ int n; cin>>n; vector>>to(n); rep(i,n-1){ int l,a; cin>>l>>a; a--; to[a].push_back({l,i+1}); } vectorans(n,-1); ans[0]=0; queueque; que.push(0); while(!que.empty()){ int x=que.front(); que.pop(); for(auto i:to[x]){ if(chmax(ans[i.second],max(ans[x],i.first))){ que.push(i.second); } } } vectorc; rep(i,n){ if(ans[i]!=-1)c.push_back(ans[i]); } sort(all(c)); int q; cin>>q; while(q--){ int t,x; cin>>t>>x; if(t==1){ cout<<(upper_bound(all(c),x)-c.begin())<