#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } int main() { int H; int W; int K; int P; while (~scanf("%d%d%d%d", &H, &W, &K, &P)) { ++H, ++W; vpii v(K); vector names(K); rep(i, K) { int y; int x; scanf("%d%d", &y, &x); char buf[101]; scanf("%s", buf); v[i] = { y,x }; names[i] = buf; } pair ans(0, 0); rep(S, 1 << K) { vector blocked(H * W); int pcnt = 0; rep(i, K) { int y, x; tie(y, x) = v[i]; if (S >> i & 1) { ++ pcnt; } else { blocked[y * W + x] = true; } } if (pcnt > P)continue; vector> dp(H, vector(W)); if(!blocked[0]) dp[0][0] = 1; rep(i, H) rep(j, W) { ll x = dp[i][j]; if (x == 0) continue; if (i + 1 < H && !blocked[(i + 1)*W + j]) dp[i + 1][j] += x; if (j + 1 < W && !blocked[i*W + (j+1)]) dp[i][j + 1] += x; } amax(ans, make_pair(dp[H - 1][W - 1], S)); } printf("%lld\n", ans.first); if (ans.first != 0) { rep(i, K) if (ans.second >> i & 1) puts(names[i].c_str()); } } return 0; }