#include #define rep(i,n) for(int i=0;i ; const int INF = 1e9; const int MOD = 1000000007; struct animal{ int x,y; string name; }; int main(){ int h,w,k,p; cin >> h >> w >> k >> p; vector friends(k); rep(i,k) cin >> friends[i].x >> friends[i].y >> friends[i].name; vector> maze(h+1,vector(w+1,false)); rep(i,k) maze[friends[i].x][friends[i].y] = true; vector ans; ll mx = 0; rep(bit,1< res; if(s != p) continue; rep(i,k){ if(bit>>i &1){ maze[friends[i].x][friends[i].y] = false; res.push_back(i); } } vector> dp(h+1,vector(w+1,0)); dp[0][0] = 1; rep(i,h+1)rep(j,w+1){ if(maze[i][j]){ dp[i][j] = 0; continue; } if(i>0) dp[i][j] += dp[i-1][j]; if(j>0) dp[i][j] += dp[i][j-1]; } for(int i:res){ maze[friends[i].x][friends[i].y] = true; } if(dp[h][w] > mx){ mx = dp[h][w]; vector empty; swap(empty,ans); for(int i:res){ ans.push_back(friends[i].name); } } } cout << mx%MOD << endl; rep(i,ans.size()){ cout << ans[i] << endl; } return 0; }