import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;


public class siesta {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream(new File("test6.txt")));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String riadok;

		while ((riadok = br.readLine()) != null) {

			int n = Integer.parseInt(riadok);
			int[] T = new int[n];
			int[] V = new int[n];
			for (int i = 0; i < n; i++) {
				String[] splited = br.readLine().split(" ");
				T[i] = Integer.parseInt(splited[0]);
				V[i] = Integer.parseInt(splited[1]);
			}
			riadok = br.readLine();
			int c = Integer.parseInt(riadok);
						
			for (int k = 0; k < c; k++) {
				String[] splited = br.readLine().split(" ");
				String R = splited[0];
				String F = splited[1];
				int L = Integer.parseInt(splited[2]);
				int count = 0;
				if (R.equals("gt")) {
					if (F.equals("min")) {
						int lastIndex = 0;
						Set<Integer> s = new TreeSet<Integer>();
						s.add(V[0]);
						for (int i = 1; i < V.length; i++) {
							if (isGreater(s, V[i])) {
								count++;
							}
							s.add(V[i]);
							while (T[i] - T[lastIndex] > L) {
								lastIndex++;
								s.remove(V[lastIndex]);
							}
						}
					}
					if (F.equals("avg")) {
						int lastIndex = 0;
						int sum = V[0];
						for (int i = 1; i < V.length; i++) {
							if (V[i] > sum/(i - lastIndex)) {
								count++;
							}
							sum += V[i];
							while (T[i] - T[lastIndex] > L) {
								lastIndex++;
								sum -= V[i];
							}
						}
					}
					if (F.equals("max")) {
						int lastIndex = 0;
						Set<Integer> s = new TreeSet<Integer>();
						s.add(V[0]);
						for (int i = 1; i < V.length; i++) {
							if (isGreater(s, V[i])) {
								count++;
							}
							s.add(V[i]);
							while (T[i] - T[lastIndex] > L) {
								lastIndex++;
								s.remove(V[lastIndex]);
							}
						}
					}
				}
				if (R.equals("lt")) {
					if (F.equals("min")) {
						int lastIndex = 0;
						Set<Integer> s = new TreeSet<Integer>();
						s.add(V[0]);
						for (int i = 1; i < V.length; i++) {
							if (isLess(s, V[i])) {
								count++;
							}
							s.add(V[i]);
							while (T[i] - T[lastIndex] > L) {
								lastIndex++;
								s.remove(V[lastIndex]);
							}
						}
					}
					if (F.equals("avg")) {
						int lastIndex = 0;
						int sum = V[0];
						for (int i = 1; i < V.length; i++) {
							if (V[i] < sum/(i - lastIndex)) {
								count++;
							}
							sum += V[i];
							while (T[i] - T[lastIndex] > L) {
								lastIndex++;
								sum -= V[i];
							}
						}
					}
					if (F.equals("max")) {
						int lastIndex = 0;
						Set<Integer> s = new TreeSet<Integer>();
						s.add(V[0]);
						for (int i = 1; i < V.length; i++) {
							if (isLess(s, V[i])) {
								count++;
							}
							s.add(V[i]);
							while (T[i] - T[lastIndex] > L) {
								lastIndex++;
								s.remove(V[lastIndex]);
							}
						}
					}
				}
				System.out.println(count);
			}
		}
	}

	private static boolean isGreater(Set<Integer> s, int i) {
		Object[] f = s.toArray();
		for (int j = 0; j < f.length; j++) {
			if ((int)f[j] >= i) {
				return false;
			}
		}
		return true;
	}
	
	private static boolean isLess(Set<Integer> s, int i) {
		Object[] f = s.toArray();
		for (int j = 0; j < f.length; j++) {
			if ((int)f[j] <= i) {
				return false;
			}
		}
		return true;
	}

}
