#include using namespace std; using ll = long long; using ld = long double; using P = pair; using vi = vector; using vl = vector; using vll = vector; using vs = vector; using vc = vector; using pll = pair; const int INF = 1e9; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct edge { int to; int cost; edge(int t, int w) : to(t), cost(w) { } }; using Graph = vector>; vector seen; int xcount = 0,lx = 0; void dfs1(const Graph &G, int v) { seen[v] = true; for (auto e : G[v]) { if (seen[e.to]) continue; else if(e.cost <= lx){ dfs1(G,e.to); xcount++; } } } int ycount = -1,ly = 0; void dfs2(const Graph &G, int v) { seen[v] = true; for (auto e : G[v]) { if (seen[e.to]) continue; else if(e.to == ly){ ycount = max(ycount,e.cost); return; } else{ ycount = max(ycount,e.cost); dfs2(G,e.to); } } } int main() { int n; cin >> n; vector> g(n); rep(i,n-1){ int l,a; cin >> l >> a; a--; g[a].push_back(edge(i+1,l)); } int q; cin >> q; rep(iii,q){ int t,x; cin >> t >> x; if(t == 1){ seen.assign(n, false); xcount = 0; lx = x; dfs1(g,0); cout << xcount+1 << endl; } else{ seen.assign(n, false); ycount = -1; x--; ly = x; dfs2(g,0); cout << ycount << endl; } } }