import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by tym12 on 10/22/16.
 */
public class Samples {

    static class Data {
        int time;
        int value;
    }

    static class Instruction {
        String op;
        String func;
        int time;
    }

    public static void main(String[] args) throws IOException {

        //Scanner scanner = new Scanner(System.in);

        // write your code here

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String nrS;
        //try {
            do {
                nrS= bufferedReader.readLine();
                //nrS = scanner.nextLine();
                if (nrS == null) break;
                int n = Integer.parseInt(nrS);

                // >>> data
                ArrayList<Data> data = new ArrayList<>(n);
                for (int i = 0; i <n ; i++) {
                    String text = bufferedReader.readLine();
                    //String text = scanner.nextLine();

                    String[] split = text.split(" ");
                    Data next = new Data(){{
                        time = Integer.parseInt(split[0]);
                        value = Integer.parseInt(split[1]);
                    }};

                    data.add(next);
                }

                // >>> instrukce
                nrS= bufferedReader.readLine();
                //nrS = scanner.nextLine();
                int in = Integer.parseInt(nrS);
                for (int i = 0; i <in ; i++) {
                    String text = bufferedReader.readLine();
                    //String text = scanner.nextLine();

                    String[] split = text.split(" ");
                    process(data, split[0], split[1], Integer.parseInt(split[2]));
                }

            }
            while(nrS != null);

    }

    private static void process(List<Data> data, String op, String func, int time) {
        int matches = 0;

        int i = 0;
        for (Data next : data) {
            if (i == 0) {
                i++;
                continue;
            }

            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            int sum = 0;
            int count = 0;

            int j = 0;
            for (Data d : data) {
                if (j == i) break;
                if (d.time >= next.time) break;
                if ((next.time - d.time) <= time) {
                    min = Math.min(min, d.value);
                    max = Math.max(max, d.value);
                    sum += d.value;
                    count++;
                }
                j++;
            }

            double val;
            if (func.equals("min")) {
                val = min;

            } else if (op.equals("max")) {
                val = max;
            } else {
                val = (double) sum / count;
            }

            if (op.equals("lt")) {
                if (next.value < val)
                    matches++;
            } else if (op.equals("gt")) {
                if (next.value > val)
                    matches++;
            }

            i++;
        }
        System.out.println(matches);
    }

    private static void old_process(List<Data> data, Instruction i) {
        int matches = 0;

        boolean first = true;
        for (Data next : data) {
            if (first) {
                first = false;
                continue;
            }

            IntSummaryStatistics stats = data.stream()
                    .filter(d -> d.time < next.time)
                    .filter(d -> (next.time - d.time) < i.time)
                    .mapToInt(d -> d.value)
                    .summaryStatistics();

            double val = 0;
            if (i.func.equals("min")) {
                val = stats.getMin();

            } else if (i.op.equals("max")) {
                val = stats.getMax();
            } else {
                val = stats.getAverage();
            }

            if (i.op.equals("lt")) {
                if (next.value < val)
                    matches++;
            } else if (i.op.equals("gt")) {
                if (next.value > val)
                    matches++;
            }

        }
        System.out.println(matches);
    }

}

