using namespace std; #include void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout< inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, star,fini) for (int i = star; i < fini; i++) #define ALL(x) std::begin(x), std::end(x) #define INF ((1LL<<62)-(1LL<<31)) #define bit(x,i)(((x)>>(i))&1) long double distance(long double xi,long double yi,long double xj,long double yj){return sqrt(1.0*((xi-xj)*(xi-xj))+1.0*((yi-yj)*(yi-yj)));} vectorneedlv(200005,-1); ll l[200005],a[200005]; void kakutei(ll pos){ if(needlv[pos]==-2)return; if(needlv[pos]!=-1)return; if(needlv[a[pos]]>-1){ needlv[pos]=max(l[pos],l[a[pos]]); } else{ needlv[pos]=-2; kakutei(a[pos]); } } void _main(){ ll n;cin >> n; l[0]=0;a[0]=0;needlv[0]=0; rep(i,1,n){ cin >> l[i] >> a[i]; a[i]--; } rep(i,0,n){ kakutei(i); } mapqone; for(ll i:needlv){ if(i<0)continue; qone[i]++; } vectorans; vectorans_name; ll prev = 0; for(auto i:qone){ ans_name.push_back(i.first); ans.push_back(prev+i.second); prev = ans.back(); } ll q;cin >> q; while (q--) { ll t,x;cin >> t; if(t==1){ cin >> x; ll pos = upper_bound(ALL(ans_name),x)-ans_name.begin(); pos--; cout<> x; cout<<(needlv[x-1]>0?needlv[x-1]:-1)<