#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, k, p, ans = 0; cin >> h >> w >> k >> p; vector name(k); vector> S(h + 1, vector(w + 1)); ll mx = 0; for(int i = 0; i < k; i++){ int y, x; cin >> y >> x >> name[i]; S[y][x] = 1 << i; } if(p){ for(int comb = (1 << p) - 1; comb < (1 << k); ){ vector> dp(h + 1, vector(w + 1)); dp[0][0] = 1; for(int y = 0; y <= h; y++){ for(int x = 0; x <= w; x++){ if((S[y][x] & comb) != S[y][x]) continue; if(y + 1 <= h) dp[y + 1][x] += dp[y][x]; if(x + 1 <= w) dp[y][x + 1] += dp[y][x]; } } if(dp[h][w] > mx){ mx = dp[h][w]; ans = comb; } int x = comb & (-comb), y = comb + x; comb = ((comb & ~y) / x >> 1) | y; } } cout << mx % 1000000007 << '\n'; for(int i = 0; i < k; i++){ if(ans >> i & 1) cout << name[i] << '\n'; } }