#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; const ll INF = 1ll<<60; const ll MOD = 1000000007; const double EPS = 1e-10; int H, W, K, P; int x[15], y[15]; string name[15]; bool done[33][33]; ll dp[33][33]; int main() { cin >> W >> H >> K >> P; REP(i, K) cin >> x[i] >> y[i] >> name[i]; pll ans = pll(0, 0); // 数, 集合 REP(s, 1<> i & 1) cnt++; if (cnt > P) continue; memset(done, 0, sizeof(done)); REP(i, K) if (!(s >> i & 1)) done[y[i]][x[i]] = true; memset(dp, 0, sizeof(dp)); dp[0][0] = !done[0][0]; REP(i, H + 1) REP(j, W + 1) { if (done[i][j]) continue; if (i > 0) dp[i][j] += dp[i - 1][j]; if (j > 0) dp[i][j] += dp[i][j - 1]; } chmax(ans, pll(dp[H][W], s)); } printf("%lld\n", ans.first % MOD); REP(i, K) if (ans.second >> i & 1) printf("%s\n", name[i].c_str()); return 0; }