#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); } int lcm(int x, int y) { return x / gcd(x, y) * y; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } int h, w, k, p; vector x, y; vector name; ll f(int mask) { vector friends; for (int i = 0; i < k; i++) { if (mask & (1 << i)) { friends.push_back(i); } } if (friends.size() != p) { return -1LL; } vector> isMove(w + 1, vector(h + 1, true)); for (int i = 0; i < k; i++) { isMove[y[i]][x[i]] = false; } for (auto i : friends) { isMove[y[i]][x[i]] = true; } vector> dp(w + 1, vector(h + 1)); dp[0][0] = 1LL; for (int i = 0; i <= w; i++) { for (int j = 0; j <= h; j++) { if (!isMove[i][j]) { continue; } dp[i][j] += 0 < i ? dp[i - 1][j] : 0; dp[i][j] += 0 < j ? dp[i][j - 1] : 0; } } return dp[w][h]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> h >> w >> k >> p; x.resize(k); y.resize(k); name.resize(k); for (int i = 0; i < k; i++) { cin >> x[i] >> y[i] >> name[i]; } ll ans = 0, ansMask = 0; for (int mask = 0; mask < (1 << k); mask++) { ll score = f(mask); if (score <= ans) { continue; } ans = score; ansMask = mask; } const ll MOD = 1e9 + 7; ans %= MOD; cout << ans << endl; for (int i = 0; i < k; i++) { if (ansMask & (1 << i)) { cout << name[i] << endl; } } return 0; }