#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using PII = pair; using PDD = pair; using PLL = pair; using VPII = vector; template using VT = vector; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back template inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;} template inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;} const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; const double EPS = 1e-9; const int MAX = 35; LL H, W, K, P, x[MAX], y[MAX]; string name[MAX]; LL dp[MAX][MAX]; vector ansNames; LL ans = 0; int main() { cin >> H >> W >> K >> P; REP(i, K) { cin >> x[i] >> y[i] >> name[i]; } REP(i, (1 << K)) { if (__builtin_popcount(i) > P) continue; set dame; REP(j, K) if ((i & (1 << j)) == 0) { dame.insert({x[j], y[j]}); } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; REP(h, H + 2) REP(w, W + 2) { if (dame.count({h + 1, w}) == 0) (dp[h + 1][w] += dp[h][w]); if (dame.count({h, w + 1}) == 0) (dp[h][w + 1] += dp[h][w]); } if (chmax(ans, dp[H][W])) { ansNames.clear(); REP(j, K) if (i & (1 << j)) { ansNames.EB(name[j]); } } } cout << ans % MOD << endl; FORE(e, ansNames) cout << e << endl; }