#include //#include //using namespace atcoder; using namespace std; const int INF = 1e9; using ll = long long; using inv = vector; using stv = vector; using pint = pair; #define FOR(i,l,r) for(int i=(l); i<(r); i++) #define rep(i,r) for(int i=0; i<(r); i++) #define repl(i,r) for(long long i=0; i<(r); i++) #define FORl(i,l,r) for(long long i=(l); i<(r); i++) #define INFL ((1LL<<62)-(1LL<<31)) #define pb(x) push_back(x) #define CIN(x) cin >> x // to and cost using Graph = vector>>; void dfs(Graph G,int v,ll nowlv, vector &lv, vector &seen){ seen[v] = true; lv[v] = nowlv; if(G[v].size() == 0) return; for(auto [nexv,l] : G[v]){ if(seen[nexv]) continue; dfs(G,nexv,max(nowlv,l),lv,seen); } } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; cin >> N; Graph G(N,vector>()); G.reserve(2*1e5); vector minl(N,-1LL); minl.reserve(2*1e5); vector seen(N,false); seen.reserve(2*1e5); seen[0] = true; rep(i,N-1){ ll L,A; cin >> L >> A; A--; G[A].pb(make_pair(i+1,L)); } dfs(G,0,1,minl,seen); // rep(i,N) cout << minl[i] << " "; // cout<< endl; vector smin; smin.reserve(2*1e5); smin = minl; sort(smin.begin(),smin.end()); ll cnt = (ll)(upper_bound(smin.begin(),smin.end(),-1)-smin.begin()); int Q; cin >> Q; rep(q,Q){ int t; cin >> t; if(t == 1){ ll x; cin >> x; ll ans= (ll)(upper_bound(smin.begin(),smin.end(),x)-smin.begin()); ans -= cnt; cout << ans << "\n"; }else{ int y; cin >> y; y--; cout << minl[y] << "\n"; } } return 0; }