#include using namespace std; #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l)) #define FORD(i, j, k, l) for(int i =(j); i >= (k); i -= (l)) #define REP(i, n) FOR(i, 0, n, 1) #define REPD(i, n) FORD(i, n, 0, 1) typedef long long ll; const ll INFF = (ll)1e18; const int INF = (int)1e9; string mapa[123]; int r, c; int comp[123][123]; pair rep[123456]; int cur = 1; int dx[] = {-1, 0, 0, 1}; int dy[] = {0, -1, 1, 0}; vector graf[12345]; string str; vector ans; int w, h; void solve(int ind) { string chars = "#."; for(int i = 0; i <= ind; i++) { ans[3*ind][i] = ans[3*ind+1][i] = ans[3*ind+2][i] = ans[h-ind-1][i] = chars[i&1]; ans[3*ind][w-i-1] = ans[3*ind+1][w-i-1] = ans[3*ind+2][w-i-1] = ans[h-ind-1][w-i-1] = chars[i&1]; } for(int i = ind; i+ind < w; i++) { ans[3*ind][i] = ans[3*ind+1][i] = ans[3*ind+2][i] = ans[h-ind-1][i] = chars[ind&1]; } for(char c = 'a'; c < str[str.size()-ind-1]+(ind == str.size()-1); c++) ans[3*ind+1][ind + 2 * (c - 'a') + 1] = chars[(ind^1)&1]; } void dfs(int x, int y) { comp[x][y] = cur; for(int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if(xx >= 0 && xx < r && yy >= 0 && yy < c && !comp[xx][yy] && mapa[x][y] == mapa[xx][yy]) dfs(xx, yy); } } void dfs2(int v, int f) { if(graf[v].size() >= 2) str += 'a' + graf[v].size()-2; for(auto u : graf[v]) if(u != f) dfs2(u, v); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> r >> c; for(int i = 0; i < r; i++) cin >> mapa[i]; for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { if(!comp[i][j]) { dfs(i, j); rep[cur] = {i, j}; cur++; } } } graf[1].push_back(0); for(int i = 2; i < cur; i++) { int nei = comp[rep[i].first-1][rep[i].second]; graf[nei].push_back(i); graf[i].push_back(nei); } for(int i = 1; i < cur; i++) { sort(graf[i].begin(), graf[i].end(), [](int i, int j){return rep[i] < rep[j];}); } dfs2(1, 0); //cerr << str << endl; w = 2 * str.size() + 100; h = 4 * str.size(); string s; for(int i = 0; i < w; i++) s += '#'; ans = vector(h, s); for(int i = 0; i < str.size(); i++) solve(i); cout << h << " " << w << endl; for(auto ss : ans) cout << ss << endl; return 0; }