using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; public class Program { public static void Main(string[] args) { new Magatro().Solve(); } } class Magatro { private int H, W, K, P; private int[] x, y; private string[] N; private void Scan() { string[] line = Console.ReadLine().Split(' '); H = int.Parse(line[0]); W = int.Parse(line[1]); K = int.Parse(line[2]); P = int.Parse(line[3]); x = new int[K]; y = new int[K]; N = new string[K]; for (int i = 0; i < K; i++) { line = Console.ReadLine().Split(' '); x[i] = int.Parse(line[0]); y[i] = int.Parse(line[1]); N[i] = line[2]; } } public void Solve() { Scan(); long max = -1; int ans = 0; for (int i = 0; i < (1 << K); i++) { if (BitCount(i) != P) { continue; } long cnt = Count(i); if (max < cnt) { ans = i; max = cnt; } } Console.WriteLine(max); for (int i = 0; i < K; i++) { int j = 1 << i; if ((ans & j) != 0) { Console.WriteLine(N[i]); } } } private long Count(int i) { var d = new Dictionary, bool>(); for (int j = 0; j < K; j++) { int k = 1 << j; if ((i & k) == 0) { d[new Pair(x[j], y[j])] = true; } } var dp = new long[H + 1, W + 1]; dp[0, 0] = 1; for (int j = 0; j <= H; j++) { for (int k = 0; k <= W; k++) { bool o; if (d.TryGetValue(new Pair(j, k), out o)) continue; if (j < H) { dp[j + 1, k] += dp[j, k]; dp[j + 1, k] %= (int)1e9 + 7; } if (k < W) { dp[j, k + 1] += dp[j, k]; dp[j, k + 1] %= (int)1e9 + 7; } } } return dp[H, W]; } private int BitCount(int n) { int cnt = 0; for (int i = 0; i < K; i++) { if (n % 2 == 1) { cnt++; } n /= 2; } return cnt; } } struct Pair { public F First; public S Second; public Pair(F f, S s) { First = f; Second = s; } }