import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); int k = sc.nextInt(); int p = sc.nextInt(); HashMap places = new HashMap<>(); String[] names = new String[k]; for (int i = 0; i < k; i++) { places.put(sc.nextInt() * 100 + sc.nextInt(), i); names[i] = sc.next(); } long max = 0; int key = 0; long[][] counts = new long[h + 1][w + 1]; for (int i = 0; i < (1 << k); i++) { if (getPop(i) != p) { continue; } counts[0][0] = 1; for (int a = 0; a <= h; a++) { for (int b = 0; b <= w; b++) { if (a == 0 && b == 0) { continue; } counts[a][b] = 0; if (places.containsKey(a * 100 + b) && ((1 << places.get(a * 100 + b)) & i) == 0) { continue; } if (a > 0) { counts[a][b] += counts[a - 1][b]; } if (b > 0) { counts[a][b] += counts[a][b - 1]; } } } if (max < counts[h][w]) { max = counts[h][w]; key = i; } } StringBuilder sb = new StringBuilder(); sb.append(max % 1000000007).append("\n"); for (int i = 0; i < k; i++) { if (key % 2 == 1) { sb.append(names[i]).append("\n"); } key /= 2; } System.out.print(sb); } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x /= 2; } return pop; } }