#include using namespace std; using ll = long long; using ld = long double; #define print(x) cerr << #x << " = " << x << endl template ostream& operator<<(ostream &out, vector &cont) { out << "["; for (const auto &x : cont) out << x << ", "; out << "]"; return out; } #define SDD 0,1 #define SDL -1,1 #define SLL -1,0 #define SUL -1,-1 #define SUU 0,-1 #define SUR 1,-1 #define SRR 1,0 #define SDR 1,1 #define A SDD,SDL #define B SDD,SLL #define C SDD,SUL #define D SDD,SUU #define E SDD,SUR #define F SDD,SRR #define G SDD,SDR #define H SDL,SLL #define I SDL,SUL #define J SUU,SRR #define K SDL,SUU #define L SDL,SUR #define M SDL,SRR #define N SDL,SDR #define O SLL,SUL #define P SLL,SUU #define Q SLL,SUR #define R SLL,SRR #define S SLL,SDR #define T SUL,SUU #define U SUL,SUR #define V SUU,SDR #define W SUR,SRR #define X SUR,SDR #define Y SUL,SRR #define Z SRR,SDR #define vv vector> void printrep(int a, int b, int c, int d){ vv rep(9, vector(9)); int x = 4, y=4, xx=4, yy=4; for (int i=0; i< 3;i++){ x += a; y += b; xx+=c; yy+=d; rep[y][x] = true; rep[yy][xx] = true; } for (int i=0; i < 9; i++){ for (int j=0; j < 9; j++){ if (i == 4 && j == 4) cout << '*'; else if (rep[i][j]) cout << '#'; else cout << '.'; } cout << '\n'; } } vv getrep(int a, int b, int c, int d){ vv ans(3); for (int i=0; i < 3;i++) ans[i].resize(3); ans[b+1][a+1] = true; ans[d+1][c+1] = true; return ans; } vector alp = { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z}; bool is_rep(int a, int b, int c, int d, vv rep){ vv newrep = getrep(a, b, c, d); for (int i=0; i < 3; i++){ for (int j=0; j < 3; j++){ if (rep[i][j] != newrep[i][j]) return false; } } return true; } int getindex(vv rep){ vv newrep = getrep(0,0,0,0); for (int i=0; i < alp.size(); i += 4){ if (is_rep(alp[i], alp[i+1], alp[i+2], alp[i+3], rep)){ return i / 4; } } } int32_t main() { int n, c; cin >> n >> c; for (int i=0; i < n; i++){ vector> table(9, vector(9)); for (int j=0; j < 9; j++){ for (int k=0; k<9;k++){ cin >> table[j][k]; } } for (int j=0; j < 9; j++){ for (int k=0; k<9;k++){ if (table[j][k] == '*'){ vector> rep(3, vector(3)); for (int l=0; l < 3;l++){ for (int m=0; m<3;m++){ if (j+l-1 < 0 || j+l-1 >= 9 || k+m-1 < 0 || k+m-1 >= 9) continue; rep[l][m] = table[j+l-1][k+m-1] == '#'; } } int in = getindex(rep); in = (in + c) % 26; printrep(alp[in*4], alp[in*4+1], alp[in*4+2], alp[in*4+3]); } } } } }