import java.util.Scanner;
import java.util.ArrayList;

public class desafio {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        int k = sc.nextInt();
        
        ArrayList<ArrayList<Integer>> col = new ArrayList<>();
        for (int i = 0; i <= m; i++) {
            col.add(new ArrayList<>());
        }
        
        int[] minCol = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            minCol[i] = 1000000000;
        }
        
        for (int idx = 0; idx < q; idx++) {
            String type = sc.next();
            if (type.equals("c")) {
                int j = sc.nextInt();
                int c = sc.nextInt();
                if (col.get(j).size() == n) {
                    System.out.println(-1);
                } else {
                    col.get(j).add(c);
                    int h = col.get(j).size();
                    if (j < minCol[h]) {
                        minCol[h] = j;
                    }
                    System.out.println(n - h + 1);
                }
            } else if (type.equals("l")) {
                int i = sc.nextInt();
                int h = n - i + 1;
                if (minCol[h] == 1000000000) {
                    System.out.println(-1);
                } else {
                    int j = minCol[h];
                    System.out.println(j + " " + col.get(j).get(h - 1));
                }
            } else if (type.equals("p")) {
                int i = sc.nextInt();
                int j = sc.nextInt();
                int h = n - i + 1;
                if (col.get(j).size() >= h) {
                    System.out.println(col.get(j).get(h - 1));
                } else {
                    System.out.println(-1);
                }
            }
        }
        sc.close();
    }
}
