#include using namespace std; using ll = long long; using PII = std::pair; using PLL = std::pair; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) const int mod = 1e9 + 7; int h, w, k, p, k2; vector> field, friendsxy; ll bfs(int x) { ll ret = 0; int c, y, bits[k]; ll dp[h + 1][w + 1]; rep(i, h + 1) rep(j, w + 1) dp[i][j] = 1; y = x; c = k; rep(i, k2) { if (y % 2 == 1) { c--; dp[friendsxy[i][0]][friendsxy[i][1]] = 0; } y /= 2; } if (c == p) { rep(i, h) dp[i + 1][0] = dp[i + 1][0] * dp[i][0]; rep(i, w) dp[0][i + 1] = dp[0][i + 1] * dp[0][i]; rep(i, h) rep(j, w) dp[i + 1][j + 1] = dp[i + 1][j + 1] * (dp[i][j + 1] + dp[i + 1][j]); ret = dp[h][w]; } return ret; } int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif int y, x; PLL ans; ll d; string name; cin >> w >> h >> k >> p; field.resize(h + 1); string friends[k]; friendsxy.resize(k); ans.first = 0, ans.second = 0; k2 = pow(2, k); rep(i, k) { cin >> x >> y >> name; friends[i] = name; friendsxy[i].push_back(y), friendsxy[i].push_back(x); } rep(i, k2) { d = bfs(i); if (ans.first < d) { ans.first = d; ans.second = i; } } cout << ans.first % mod << endl; if (ans.first != 0){ d = ans.second; rep(i, k) { if (d % 2 == 0) cout << friends[i] << endl; d /= 2; } } return 0; }