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 {

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

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String nrS;
        while ((nrS = bufferedReader.readLine()) != null){
            int n = Integer.parseInt(nrS);

            // >>> data
            int[] times = new int[n];
            int[] vals = new int[n];

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

                String[] split = text.split(" ");
                times[i] = Integer.parseInt(split[0]);
                vals[i] = Integer.parseInt(split[1]);
            }

            // >>> 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(times, vals, split[0], split[1], Integer.parseInt(split[2]));
            }

        };

    }

    private static void process(int[] times, int[] vals, String op, String func, int time) {
        int matches = 0;

        for (int i = 1; i < times.length; i++) {
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            int sum = 0;
            int count = 0;

            int itime = times[i];
            int ival = vals[i];

            for (int j = 1; j < times.length; j++) {
                int dtime = times[j];
                int dvalue = vals[j];

                if (j == i) break;
                if (dtime >= itime) break;
                if ((itime - dtime) <= time) {
                    min = Math.min(min, dvalue);
                    max = Math.max(max, dvalue);
                    sum += dvalue;
                    count++;
                }
            }

            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 (ival < val)
                    matches++;
            } else if (op.equals("gt")) {
                if (ival > val)
                    matches++;
            }
        }
        System.out.println(matches);
    }

}

