import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); List> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } int[] levels = new int[n]; for (int i = 1; i < n; i++) { levels[i] = sc.nextInt(); int x = sc.nextInt() - 1; graph.get(x).add(i); } TreeMap counts = new TreeMap<>(); Deque deq = new ArrayDeque<>(); deq.add(new Path(0, 1)); boolean[] visited = new boolean[n]; while (deq.size() > 0) { Path p = deq.poll(); p.value = Math.max(p.value, levels[p.idx]); levels[p.idx] = p.value; visited[p.idx] = true; counts.put(p.value, counts.getOrDefault(p.value, 0) + 1); for (int x : graph.get(p.idx)) { deq.add(new Path(x, p.value)); } } int current = 0; for (int x : counts.keySet()) { current += counts.get(x); counts.put(x, current); } int q = sc.nextInt(); String result = IntStream.range(0, q).mapToObj(i -> { int type = sc.nextInt(); int x = sc.nextInt(); if (type == 1) { return counts.floorEntry(x).getValue().toString(); } else { return visited[x - 1] ? String.valueOf(levels[x - 1]) : "-1"; } }).collect(Collectors.joining("\n")); System.out.println(result); } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }