#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) begin(v), end(v) using namespace std; using P = pair; using ll = long long; using vi = vector; using vll = vector; int main() { int n,q; cin >> n; int l[n+1][2]; for(int i = 2; i <= n;i++) cin >> l[i][0] >> l[i][1]; int level[n+1]; rep(i,n+1) level[i] = -1; level[1] = 0; for(int j = 2;j <= n; j++){ int waza = j; int check_waza[n+1]; rep(k,n+1) check_waza[k] = 0; while(1){ level[j] = max(l[waza][0],level[j]); check_waza[waza]++; waza = l[waza][1]; if(waza == 1) break; else if(check_waza[waza] == 2){ level[j] = -1; break; } } } cin >> q; rep(i,q){ int t,x; ll ans = 0; cin >> t >> x; if(t == 1){ rep(j,n+1) if(x >= level[j] && level[j] != -1) ans++; }else{ ans = level[x]; } cout << ans <