import java.util.Scanner;

public class Gric {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int R = scan.nextInt();
		int Q = scan.nextInt();

		if (R == 1) {
			int[] niz = new int[W + 1];
			for (int i = 0; i < Q; i++) {
				byte a = scan.nextByte();
				if (a == 1) {
					int w = scan.nextInt();
					int h = scan.nextInt();
					if (h == H) {
						niz[w] = 1;
					}
				} else {
					int w = scan.nextInt();
					System.out.println(W - niz[w]);
				}
			}
		} else if (R == 2) {
			double m = Math.sqrt(3) - 1;
			double[] niz = new double[W + 4];
			for (int i = 0; i < Q; i++) {
				byte a = scan.nextByte();
				if (a == 1) {
					int w = scan.nextInt() + 2;

					int h = scan.nextInt();
					if (h == H + 1) {
						if (niz[w + 1] < m) {
							niz[w + 1] = m;
						}

						if (niz[w - 1] < m) {
							niz[w - 1] = m;
						}

						niz[w] = 1;

					} else {
						if (niz[w + 1] < 1 + 1) {
							niz[w + 1] = 1 + m;
						}

						if (niz[w - 1] != 1 + 1) {
							niz[w - 1] = 1 + m;
						}

						niz[w] = 2;
					}
				} else {
					int w = scan.nextInt();
					System.out.println(H - niz[w + 2]);
				}
			}
		}

	}

}