#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n;
    vector<vector<int>> g(n);
    vector<int> l(n);
    rep(i,n-1){
        int a;
        cin >> l[i+1] >> a;
        g[a-1].push_back(i+1);
    }
    vector<int> dist(n,INF), r(1,0);
    dist[0] = 0;
    priority_queue<asc(P)> pq;
    pq.push({0,0});
    while(pq.size()){
        int now, d;
        tie(d,now) = pq.top();
        pq.pop();
        if(dist[now]!=d) continue;
        r.push_back(d);
        for(int x:g[now]){
            if(chmin(dist[x], max(dist[now], l[x]))) pq.push({dist[x], x});
        }
    }
    rep(i,n) if(dist[i]==INF) dist[i] = -1;
    cin >> q;
    rep(houren,q){
        int t,x;
        cin >> t >> x;
        if(t==1){
            cout << upper_bound(all(r),x) - r.begin()-1 << '\n';
        }else{
            cout << dist[x-1] << '\n';
        }
    }
    return 0;
}