#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; struct Friend { int x; int y; string name; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, K, P; cin >> H >> W >> K >> P; vector f(K); for (ll i = 0; i < K; i++) { cin >> f[i].x >> f[i].y >> f[i].name; } const int maximum = 1LL << K; ll maxi = 0; ll maxf = -1; for (ll i = 0; i < maximum; i++) { vector> ok(H + 1, vector(W + 1, true)); vector> dp(H + 1, vector(W + 1, 1)); ll num = i; int cnt = 0; for (int j = 0; j < K; j++) { if (num % 2 == 1) { ok[f[j].x][f[j].y] = false; dp[f[j].x][f[j].y] = 0; } else { cnt++; } num /= 2; } if (cnt > P) { continue; } for (int x = 1; x <= H; x++) { for (int y = 1; y <= W; y++) { if (ok[x][y]) { dp[x][y] = (dp[x - 1][y] + dp[x][y - 1]) % MOD; } } } if (maxi < dp[H][W]) { maxi = dp[H][W]; maxf = i; } } cout << maxi << endl; if (maxi > 0) { for (int i = 0; i < K; i++) { if (maxf % 2 == 0) { cout << f[i].name << endl; } maxf /= 2; } } return 0; }