#include using namespace std; typedef long long int64; const int mod = 1e9 + 7; int H, W, K, P; int A[33][33]; string Q[15]; int64 dp[33][33]; int64 rec(int y, int x, int bit) { if(y > H || x > W) return (0LL); if(~A[y][x] && (~bit >> A[y][x]) & 1) return (0LL); if(y == H && x == W) return (1LL); if(~dp[y][x]) return (dp[y][x]); return (dp[y][x] = rec(y + 1, x, bit) + rec(y, x + 1, bit)); } int main() { memset(A, -1, sizeof(A)); cin >> H >> W >> K >> P; for(int i = 0; i < K; i++) { int y, x; cin >> y >> x >> Q[i]; A[y][x] = i; } int64 latte = rec(0, 0, 0), malta = 0; for(int i = 1; i < 1 << K; i++) { if(__builtin_popcount(i) > P) continue; memset(dp, -1, sizeof(dp)); auto pp = rec(0, 0, i); if(pp > latte) { latte = pp; malta = i; } } cout << latte % mod << endl; for(int i = 0; i < 1 << K; i++) { if((malta >> i) & 1) cout << Q[i] << endl; } }