#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T& x, const T& y){return (x bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; int main(){ int n; cin >> n; VVI g(n); VI l(n), a(n); REP(i,n-1){ cin >> l[i+1] >> a[i+1], a[i+1]--; g[a[i+1]].push_back(i+1); } VI ls(n,INF), mls(n,-1); function dfs=[&](int v, int m){ ls[v]=m; mls[v]=m; for(auto to:g[v]){ dfs(to,max(m,(int)l[to])); } }; dfs(0,0); sort(ALL(ls)); int q; cin >> q; int t, x; REP(i,q){ cin >> t >> x; if(t==1) cout << upper_bound(ALL(ls),x)-ls.begin() << endl; else cout << mls[x-1] << endl; } return 0; }