#include using namespace std; using ll = long long; constexpr ll mod = 1e18 + 3; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, U, H, W; cin >> N >> U >> H >> W; int HW = H * W; vector F(N); vector S(N); for(int x = 0; x < N; ++x) { cin >> F[x]; for(int i = 0; i < H; ++i) { string T; cin >> T; S[x] += T; } } vector p2(HW); p2[0] = 1; for(int i = 1; i < HW; ++i) { p2[i] = p2[i - 1] * 2; if(p2[i] >= mod) p2[i] -= mod; } unordered_map m; unordered_map> ms; for(int x = 0; x < N; ++x) { ll h = 0; for(int i = 0; i < HW; ++i) if(S[x][i] == '#') { h += p2[i]; if(h >= mod) h -= mod; } if(m.find(h) == m.end()) ms[h] = make_pair(x, -1); m[h] += (x < U ? 1 : -1); if(F[x] == 0) continue; for(int i = 0; i < HW; ++i) { ll hi = h + (S[x][i] == '#' ? -1 : 1) * p2[i]; if(hi < 0) hi += mod; if(hi >= mod) hi -= mod; if(m.find(hi) == m.end()) ms[hi] = make_pair(x, i); m[hi] += (x < U ? 1 : -1); } } ll val_max = -1e9, h_max = -1; pair ans; for(int i = 0; i < (1 << min(25, HW)); ++i) if(m.find(i) == m.end()) { val_max = 0; h_max = i; ans = make_pair(-1, -1); break; } for(auto [h, val] : m) if(val_max < val) { val_max = val; h_max = h; ans = ms[h]; } cout << val_max << "\n"; auto [x, p] = ans; if(x == -1) { for(int i = 0; i < HW; ++i) { if(h_max >> i & 1) cout << '#'; else cout << '.'; if(i % W == W - 1) cout << "\n"; } } else { for(int i = 0; i < HW; ++i) { if(i != p) cout << S[x][i]; else if(S[x][i] == '#') cout << '.'; else cout << '#'; if(i % W == W - 1) cout << "\n"; } } return 0; }