import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); String[] ids = new String[n]; int[] lefts = new int[n]; int[] rights = new int[n]; HashMap> logs = new HashMap<>(); TreeMap compress = new TreeMap<>(); compress.put(0, null); for (int i = 0; i < n; i++) { ids[i] = sc.next(); lefts[i] = sc.nextInt(); rights[i] = sc.nextInt() + 1; if (!logs.containsKey(ids[i])) { logs.put(ids[i], new TreeMap<>()); } logs.get(ids[i]).put(lefts[i], rights[i]); compress.put(lefts[i], null); compress.put(rights[i], null); } int q = sc.nextInt(); int[] types = new int[q]; String[] students = new String[q]; int[] times = new int[q]; int[] starts = new int[q]; int[] ends = new int[q]; for (int i = 0; i < q; i++) { types[i] = sc.nextInt(); if (types[i] == 1) { students[i] = sc.next(); times[i] = sc.nextInt(); } else if (types[i] == 2) { times[i] = sc.nextInt(); } else { students[i] = sc.next(); starts[i] = sc.nextInt(); ends[i] = sc.nextInt() + 1; compress.put(starts[i], null); compress.put(ends[i], null); } } int idx = 1; for (int x : compress.keySet()) { compress.put(x, idx++); } BinaryIndexedTree bit = new BinaryIndexedTree(idx); for (int i = 0; i < n; i++) { bit.add(compress.get(lefts[i]), 1); bit.add(compress.get(rights[i]), -1); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { if (types[i] == 1) { if (!logs.containsKey(students[i]) || logs.get(students[i]).floorEntry(times[i]) == null || logs.get(students[i]).floorEntry(times[i]).getValue() <= times[i]) { sb.append("No\n"); } else { sb.append("Yes\n"); } } else if (types[i] == 2) { sb.append(bit.getSum(compress.floorEntry(times[i]).getValue())).append("\n"); } else { if (!logs.containsKey(students[i])) { logs.put(students[i], new TreeMap<>()); } logs.get(students[i]).put(starts[i], ends[i]); bit.add(compress.get(starts[i]), 1); bit.add(compress.get(ends[i]), -1); } } System.out.print(sb); } } class BinaryIndexedTree { int size; int[] tree; public BinaryIndexedTree(int size) { this.size = size; tree = new int[size]; } public void add(int idx, int value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] += value; idx += mask; } mask <<= 1; } } public int getSum(int from, int to) { return getSum(to) - getSum(from - 1); } public int getSum(int x) { int mask = 1; int ans = 0; while (x > 0) { if ((x & mask) != 0) { ans += tree[x]; x -= mask; } mask <<= 1; } return ans; } } 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(); } }