#include using namespace std; #define rep(i, a, b) for (int i=a;i<(b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vvi; map, char> m{ {{2, 1}, {'a'}}, {{2, 4}, {'b'}}, {{2, 7}, {'c'}}, {{2, 8}, {'d'}}, {{9, 2}, {'e'}}, {{6, 2}, {'f'}}, {{3, 2}, {'g'}}, {{1, 4}, {'h'}}, {{7, 1}, {'i'}}, {{6, 8}, {'j'}}, {{8, 1}, {'k'}}, {{9, 1}, {'l'}}, {{6, 1}, {'m'}}, {{3, 1}, {'n'}}, {{7, 4}, {'o'}}, {{8, 4}, {'p'}}, {{9, 4}, {'q'}}, {{6, 4}, {'r'}}, {{3, 4}, {'s'}}, {{8, 7}, {'t'}}, {{9, 7}, {'u'}}, {{3, 8}, {'v'}}, {{6, 9}, {'w'}}, {{3, 9}, {'x'}}, {{6, 7}, {'y'}}, {{6, 3}, {'z'}}, }; map> im{ {{'a'}, {2, 1}}, {{'b'}, {2, 4}}, {{'c'}, {2, 7}}, {{'d'}, {2, 8}}, {{'e'}, {9, 2}}, {{'f'}, {6, 2}}, {{'g'}, {3, 2}}, {{'h'}, {1, 4}}, {{'i'}, {7, 1}}, {{'j'}, {6, 8}}, {{'k'}, {8, 1}}, {{'l'}, {9, 1}}, {{'m'}, {6, 1}}, {{'n'}, {3, 1}}, {{'o'}, {7, 4}}, {{'p'}, {8, 4}}, {{'q'}, {9, 4}}, {{'r'}, {6, 4}}, {{'s'}, {3, 4}}, {{'t'}, {8, 7}}, {{'u'}, {9, 7}}, {{'v'}, {3, 8}}, {{'w'}, {6, 9}}, {{'x'}, {3, 9}}, {{'y'}, {6, 7}}, {{'z'}, {6, 3}}, }; int main() { cin.tie(0)->sync_with_stdio(0); int N, C; cin >> N >> C; for (int i = 0; i < N; i++) { set dir; string s; for (int j = 0; j < 3; j++) cin >> s; cin >> s; if (s[3] == '#') dir.insert(7); if (s[4] == '#') dir.insert(8); if (s[5] == '#') dir.insert(9); cin >> s; if (s[3] == '#') dir.insert(4); if (s[4] == '#'); if (s[5] == '#') dir.insert(6); cin >> s; if (s[3] == '#') dir.insert(1); if (s[4] == '#') dir.insert(2); if (s[5] == '#') dir.insert(3); for (int j = 0; j < 3; j++) cin >> s; char c = (m[dir] + C - 'a') % 26 + 'a'; auto r = im[c]; vector> canvas (9, vector(9, '.')); canvas[4][4] = '*'; if(r.contains(7)) { canvas[1][1] = '#'; canvas[2][2] = '#'; canvas[3][3] = '#'; } if(r.contains(8)) { canvas[1][4] = '#'; canvas[2][4] = '#'; canvas[3][4] = '#'; } if(r.contains(9)) { canvas[1][7] = '#'; canvas[2][6] = '#'; canvas[3][5] = '#'; } if(r.contains(4)) { canvas[4][1] = '#'; canvas[4][2] = '#'; canvas[4][3] = '#'; } if(r.contains(6)) { canvas[4][5] = '#'; canvas[4][6] = '#'; canvas[4][7] = '#'; } if(r.contains(1)) { canvas[5][3] = '#'; canvas[6][2] = '#'; canvas[7][1] = '#'; } if(r.contains(2)) { canvas[5][4] = '#'; canvas[6][4] = '#'; canvas[7][4] = '#'; } if(r.contains(3)) { canvas[5][5] = '#'; canvas[6][6] = '#'; canvas[7][7] = '#'; } for(const auto &line: canvas) { cout << string(all(line)) << '\n'; } } }