#include // #include // #include using namespace std; // using namespace atcoder; #define SZ(x) (int)(x).size() #define dout(x) printf("%.10f\n", (double)(x)) #define ALL(s) (s).begin(), (s).end() #define so(V) sort(ALL(V)) #define rev(V) reverse(ALL(V)) typedef pair P; typedef pair Pl; typedef vector> vvi; typedef vector> vvl; long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } /* lcm (a, b) : 2整数版 入力:整数 a, b 出力:aとbの最小公倍数 */ long lcm(long a, long b) { long d = gcd(a, b); return a / d * b; } int main() { long N, Q, a, b; cin >> N; vector> waza(N); vector saisyou(N, -1), canln(N, 1); for (int i = 1; i < N; i++) { cin >> a >> b; b--; waza[b].push_back({i, a}); } saisyou[0] = 0; canln[0] = 0; queue que; que.push({0, 0}); while (!que.empty()) { long nx = que.front().first; long ny = que.front().second; que.pop(); saisyou[nx] = ny; for (int i = 0; i < SZ(waza[nx]); i++) { if (canln[waza[nx][i].first] == 1) { canln[waza[nx][i].first] = 0; que.push({waza[nx][i].first, max(ny, waza[nx][i].second)}); } } } map level, anslevel; vector anslevelmin; for (int i = 0; i < N; i++) { if (saisyou[i] == -1) { continue; } if (level.count(saisyou[i])) { level[saisyou[i]]++; } else { level[saisyou[i]] = 1; } } long ans = 0; for (auto val : level) { ans += val.second; anslevel[val.first] = ans; anslevelmin.push_back(val.first); } cin >> Q; for (int i = 0; i < Q; i++) { cin >> a >> b; if (a == 1) { auto itl = upper_bound(ALL(anslevelmin), b); itl--; cout << anslevel[*itl] << endl; } else { b--; cout << saisyou[b] << endl; } } return 0; }