#include <bits/stdc++.h>
#include "atcoder/modint"

using i64 = long long;
using Fp = atcoder::modint998244353;

int main() {
    int N;
    std::cin >> N;
    std::vector<int> L(N), A(N);
    std::vector<std::vector<int>> graph(N);
    for (int i = 1; i < N; ++i) {
        std::cin >> L[i] >> A[i];
        --A[i];
        graph[A[i]].push_back(i);
    }
    std::vector<int> dist(N, -1);
    dist[0] = 0;
    std::queue<int> que;
    que.push(0);
    while (not que.empty()) {
        const auto f = que.front();
        que.pop();
        for (const auto t : graph[f]) {
            i64 c = std::max(dist[f], L[t]);
            dist[t] = c;
            que.push(t);
        }
    }
    std::vector<i64> x;
    for (const auto e : dist) if (e != -1) x.push_back(e);
    std::sort(x.begin(), x.end());

    int Q;
    std::cin >> Q;
    while (Q--) {
        int t;
        std::cin >> t;
        if (t == 1) {
            int v;
            std::cin >> v;
            auto itr = std::upper_bound(x.begin(), x.end(), v);
            std::cout << (itr - x.begin()) << std::endl;
        } else {
            int v;
            std::cin >> v;
            --v;
            std::cout << dist[v] << std::endl;
        }
    }
}