import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static ArrayList> graph = new ArrayList<>(); static int[] levels; static int[] needs; static TreeMap counts = new TreeMap<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } levels = new int[n]; for (int i = 1; i < n; i++) { levels[i] = sc.nextInt(); graph.get(sc.nextInt() - 1).add(i); } needs = new int[n]; Arrays.fill(needs, -1); setNeeds(0, 0, 0); counts.put(0, 1); int current = 0; for (int x : counts.keySet()) { current += counts.get(x); counts.put(x, current); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { int type = sc.nextInt(); int x = sc.nextInt(); if (type == 1) { sb.append(counts.floorEntry(x).getValue()).append("\n"); } else { sb.append(needs[x - 1]).append("\n"); } } System.out.print(sb); } static void setNeeds(int idx, int p, int v) { needs[idx] = Math.max(v, levels[idx]); counts.put(needs[idx], counts.getOrDefault(needs[idx], 0) + 1); for (int x : graph.get(idx)) { if (p != x) { setNeeds(x, idx, needs[idx]); } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }