import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.RestoreAction;

public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String q = "";
		while ((q = br.readLine()) != null) {

			if (q.equals(""))
				break;

			int numbers = new Scanner(q).nextInt();

			Map<Integer, Integer> all = new TreeMap<Integer, Integer>();

			int arr[][] = new int[numbers][2];
			int cou = 0;
			String line;
			for (int i = 0; i < numbers; i++) {
				line = br.readLine();
				Scanner sc = new Scanner(line);
				arr[cou][0] = sc.nextInt();
				arr[cou++][1] = sc.nextInt();
			}

			numbers = new Scanner(br.readLine()).nextInt();

			int result[] = new int[numbers];

			for (int i = 0; i < numbers; i++) {
				line = br.readLine();
				Scanner sc = new Scanner(line);

				String first = sc.next();
				String second = sc.next();
				int time = sc.nextInt();

				int numberOfSamples = 0;

				if (second.equals("avg")) {

					int length = arr.length;

					for (int q1 = 1; q1 < length; q1++) {

						int sum = 0;
						int count = 0;

						for (int qw = q1 - 1; qw > 0; qw--) {

							if (arr[qw][0] + time < arr[q1][0]) {
								break;
							}
							count++;
							sum += arr[qw][1];
						}

						if (count != 0) {
							if (first.equals("gt")) {
								if (arr[q1][1] > (sum / count)) {
									numberOfSamples++;
								}
							} else {
								if (arr[q1][1] < (sum / count)) {
									numberOfSamples++;
								}
							}
						}
					}

				} else if (second.equals("min")) {

					int length = arr.length;

					for (int q1 = 1; q1 < length; q1++) {

						int min = Integer.MAX_VALUE;

						for (int qw = q1 - 1; qw > 0; qw--) {

							if (arr[qw][0] + time < arr[q1][0]) {
								break;
							}
							min = Math.min(min, arr[qw][1]);
						}

						if (first.equals("gt")) {
							if (arr[q1][1] > min) {
								numberOfSamples++;
							}
						} else {
							if (arr[q1][1] < min) {
								numberOfSamples++;
							}
						}
					}

				} else {
					int length = arr.length;

					for (int q1 = 1; q1 < length; q1++) {

						int max = 0;

						for (int qw = q1 - 1; qw > 0; qw--) {

							if (arr[qw][0] + time < arr[q1][0]) {
								break;
							}
							max = Math.max(max, arr[qw][1]);
						}

						if (first.equals("gt")) {
							if (arr[q1][1] > max) {
								numberOfSamples++;
							}
						} else {
							if (arr[q1][1] < max) {
								numberOfSamples++;
							}
						}
					}
				}

				result[i] = numberOfSamples;

			}

			for (int m = 0; m < result.length; m++) {

				System.out.println(result[m]);

			}
		}

	}
}
