// JAI SHREE RAM /* ░██████╗░█████╗░░██████╗░███╗░░██╗██╗██╗░░██╗░██████╗░██╗░░██╗░█████╗░░██████╗██╗░░██╗░█████╗░██████╗░███████╗ ██╔════╝██╔══██╗██╔════╝░████╗░██║██║██║░██╔╝██╔════╝░██║░░██║██╔══██╗██╔════╝██║░░██║██╔══██╗██╔══██╗╚════██║ ╚█████╗░███████║██║░░██╗░██╔██╗██║██║█████═╝░██║░░██╗░███████║██║░░██║╚█████╗░███████║██║░░╚═╝██████╔╝░░░░██╔╝ ░╚═══██╗██╔══██║██║░░╚██╗██║╚████║██║██╔═██╗░██║░░╚██╗██╔══██║██║░░██║░╚═══██╗██╔══██║██║░░██╗██╔══██╗░░░██╔╝░ ██████╔╝██║░░██║╚██████╔╝██║░╚███║██║██║░╚██╗╚██████╔╝██║░░██║╚█████╔╝██████╔╝██║░░██║╚█████╔╝██║░░██║░░██╔╝░░ ╚═════╝░╚═╝░░╚═╝░╚═════╝░╚═╝░░╚══╝╚═╝╚═╝░░╚═╝░╚═════╝░╚═╝░░╚═╝░╚════╝░╚═════╝░╚═╝░░╚═╝░╚════╝░╚═╝░░╚═╝░░╚═╝░░░ */ import java.util.*; import java.util.Map.Entry; import java.util.stream.*; import java.lang.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.io.*; public class Main { static Scanner sc = new Scanner(System.in); static FastScanner fs = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static final Random random = new Random(); static final int mod = 1_000_000_007; static final int MAXN = 1000001; static StringBuilder sb = new StringBuilder(); static final int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 }; static final int[] dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 }; static final int[] dx9 = { -1, -1, -1, 0, 0, 0, 1, 1, 1 }, dy9 = { -1, 0, 1, -1, 0, 1, -1, 0, 1 }; static final double eps = 1e-10; static long [] larr = new long[100001]; static int cnt = 0, tmpSum = 0; private static void sagnik() throws IOException { int N = fs.nextInt(); ArrayList> graph = new ArrayList<>(N); for (int i = 0;i < N;++ i) graph.add(new ArrayList<>()); int[] L = new int[N]; L[0] = 1; final int INF = 1 << 30; for (int i = 1;i < N;++ i) { int l = fs.nextInt(), A = fs.nextInt() - 1; graph.get(A).add(i); L[i] = l + INF; } int Q = fs.nextInt(); class Pair { int vertex; int level; Pair(int v) { vertex = v; level = L[v]; } } PriorityQueue pq = new PriorityQueue<>((l, r) -> Integer.compare(l.level, r.level)); pq.add(new Pair(0)); TreeMap ans = new TreeMap<>(); ans.put(0, 0); while(!pq.isEmpty()) { Pair p = pq.poll(); if (L[p.vertex] < p.level) continue; int now = p.vertex; if (ans.get(p.level) == null) ans.put(p.level, ans.lastEntry().getValue()); ans.merge(p.level, 1, (l, r) -> l + r); for (int next : graph.get(now)) { if (L[next] <= L[now]) continue; L[next] = L[next] >= INF ? Math.max(L[next] - INF, L[now]) : L[now]; pq.add(new Pair(next)); } } while(Q --> 0) { if (fs.nextInt() == 1) { int x = fs.nextInt(); out.println(ans.floorEntry(x).getValue()); } else { int y = fs.nextInt() - 1; out.println(L[y] >= INF ? -1 : L[y]); } } out.flush(); } public static void main(String[] args) throws IOException { int t = 1; while(t-->0) sagnik(); } // Make t = 1 baby // dont worry bout me, i'm not high private static int arrMax(int[] A) {return Arrays.stream(A).max().getAsInt();} private static int arrMin(int[] A) {return Arrays.stream(A).min().getAsInt();} private static int arrSum(int[] A) {return Arrays.stream(A).sum();} private static int countNumInArr(int[] A, int n) {return (int) Arrays.stream(A).filter(x -> x == n).count();} private static void swap(int[] A, int i, int j) { int temp = A[i]; A[i] = A[j]; A[j] = temp; } private static void reverse(int[] A) {int s=0,e=A.length-1;while(s0){++count; number &= number-1;} return count;} private static boolean isEven(int i) { return (i & 1) == 0; } private static boolean isVowel(char c) { return c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U';} private static boolean isPrime(int x) {if(x==1) return false; for(int i=2; i*i<=x; i++){if(x%i==0) return false;} return true;} public static boolean[] genSieve(int n) {boolean[] A = new boolean[n+1]; for(int i=0;i x) {return x.stream().mapToInt(i -> i).toArray();} private static int[] setArray(int n) {int A[]=new int[n]; for(int i=0;i x) {for(int i : x) {System.out.print(i+" ");}} private static void prtArr(int[] A) {System.out.println(Arrays.toString(A));} private static void prtArrWithSpce(int[] A) {for(int i=0;i