import java.io.BufferedReader;
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)  {

        //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();
                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(" ");
                    Instruction instruction = new Instruction(){{
                        op = split[0];
                        func = split[1];
                        time = Integer.parseInt(split[2]);
                    }};

                    process(data, instruction);
                }

            }
            while(nrS != null);
        } catch (Exception e) {
            //
        }

    }

    private static void 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);
    }

    private static Set<Character> toSet(String text) {
        return text.chars().mapToObj(c -> (char) c).collect(Collectors.toSet());
    }

}

