import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by tym18 on 10/22/16.
 */
public class Samples2 {
    public static BufferedReader in;
    public static int[][] values;
    public static Command[] commands;
    public static int[] resNum;

    public static void main(String[] args) {
        in = new BufferedReader(new InputStreamReader(System.in));

        String line;
        try {
            while ((line = in.readLine()) != null)
            {
                //get values
                int valCount = Integer.parseInt(line);
                values = new int[valCount][2];
                for (int i = 0; i < valCount; i++) {
                    line = in.readLine();
                    String[] parsedLine = line.split(" ");
                    values[i][0] = Integer.parseInt(parsedLine[0]);
                    values[i][1] = Integer.parseInt(parsedLine[1]);
                }

                //get commands
                line = in.readLine();
                int cmdCount = Integer.parseInt(line);
                commands = new Command[cmdCount];
                for (int i = 0; i < cmdCount; i++) {
                    line = in.readLine();
                    String[] parsedLine = line.split(" ");
                    commands[i] = new Command(parsedLine[0].charAt(0), parsedLine[1].charAt(1), Integer.parseInt(parsedLine[2]));
                }

                //set results count
                resNum = new int[cmdCount];

                for (int i = 0; i < valCount; i++) {
                    if(i != 0)
                        executeCmds(cmdCount, i);
                    updateValues();
                }

                for (int res :
                        resNum) {
                    System.out.println(res);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void updateValues() {

    }

    private static void executeCmds(int cmdCount, int valInProcess) {
        for (int i = 0; i < cmdCount; i++) {
            switch (commands[i].fnc)
            {
                case 'i':
                    //min
                    //check if at least one value will be processed
                    if((values[valInProcess][0] - values[valInProcess - 1][0]) > commands[i].time)
                        break;
                    //get value to be compared with
                    int min = getMinVal(valInProcess, commands[i].time);
                    //compare
                    switch (commands[i].cmp)
                    {
                        case 'g':   //greater than
                            if(values[valInProcess][1] > min)
                                resNum[i]++;
                            break;
                        case 'l':   //less than
                            if(values[valInProcess][1] < min)
                                resNum[i]++;
                            break;
                    }
                    break;
                case 'a':
                    //max
                    //check if at least one value will be processed
                    if((values[valInProcess][0] - values[valInProcess - 1][0]) > commands[i].time)
                        break;
                    //get value to be compared with
                    int max = getMaxVal(valInProcess, commands[i].time);
                    //compare
                    switch (commands[i].cmp)
                    {
                        case 'g':   //greater than
                            if(values[valInProcess][1] > max)
                                resNum[i]++;
                            break;
                        case 'l':   //less than
                            if(values[valInProcess][1] < max)
                                resNum[i]++;
                            break;
                    }
                    break;
                case 'v':
                    //avg
                    //check if at least one value will be processed
                    if((values[valInProcess][0] - values[valInProcess - 1][0]) > commands[i].time)
                        break;
                    //get value to be compared with
                    float avg = getAvgVal(valInProcess, commands[i].time);
                    //compare
                    switch (commands[i].cmp)
                    {
                        case 'g':   //greater than
                            if(values[valInProcess][1] > avg)
                                resNum[i]++;
                            break;
                        case 'l':   //less than
                            if(values[valInProcess][1] < avg)
                                resNum[i]++;
                            break;
                    }
                    break;
            }
        }
    }

    private static float getAvgVal(int valInProcess, int time) {
        int avgSum = values[valInProcess - 1][1];   //get first value before the currently processed
        int valProcessed = 1;

        for (int i = valInProcess - 2; i >= 0; i--) {
            if((values[valInProcess][0] - values[i][0]) > time)
                break;

            avgSum += values[i][1];
            valProcessed++;
        }

        return (float)avgSum / (float)valProcessed;
    }

    private static int getMaxVal(int valInProcess, int time) {
        int val = values[valInProcess - 1][1];  //get first value before the currently processed

        for (int i = valInProcess - 2; i >= 0; i--) {
            if((values[valInProcess][0] - values[i][0]) > time)
                break;

            if(values[i][1] > val)
            {
                val = values[i][1];
            }
        }

        return val;
    }

    private static int getMinVal(int valInProcess, int time) {
        int val = values[valInProcess - 1][1];  //get first value before the currently processed

        for (int i = valInProcess - 2; i >= 0; i--) {
            if((values[valInProcess][0] - values[i][0]) > time)
                break;

            if(values[i][1] < val)
            {
                val = values[i][1];
            }
        }

        return val;
    }

    static class Command{
        char cmp;
        char fnc;
        int time;

        public Command(char cmp, char fnc, int time) {
            this.cmp = cmp;
            this.fnc = fnc;
            this.time = time;
        }
    }
}
