#include using namespace std; using ll = long long; using T = bitset<10000>; int main() { ios::sync_with_stdio(false); cin.tie(0); string str; int N, U, H, W, v; cin >> N >> U >> H >> W; vector> tb; for(int i = 0; i < N; i++){ cin >> v; T S; for(int y = 0; y < H; y++){ cin >> str; for(int x = 0; x < W; x++){ if(str[x] == '#') S[y * W + x] = 1; } } if(i < U){ tb.emplace_back(S, true); if(v == 1){ for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ S.flip(y * W + x); tb.emplace_back(S, true); S.flip(y * W + x); } } } }else{ tb.emplace_back(S, false); if(v == 1){ for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ S.flip(y * W + x); tb.emplace_back(S, false); S.flip(y * W + x); } } } } } sort(tb.begin(), tb.end(), [&](pair lhs, pair rhs){ for(int i = 0; i < H * W; i++){ if(lhs.first[i] < rhs.first[i]) return true; } return false; }); int ans = -1; T S = 0; for(int i = 0; i < tb.size(); ){ int p = i, cnt = 0; while(i < tb.size() && tb[i].first == tb[p].first){ cnt += tb[i].second ? 1 : -1; i++; } if(cnt > ans){ ans = cnt; S = tb[p].first; } } cout << ans << '\n'; for(int y = 0; y < H; y++){ for(int x = 0; x < W; x++){ cout << (S[y * W + x] ? '#' : '.'); } cout << '\n'; } }