#include using namespace std; typedef long long ll; typedef double ld; constexpr ll TOP = 0; constexpr ll TOPRIGHT = 1; constexpr ll RIGHT = 2; constexpr ll DOWNRIGHT = 3; constexpr ll DOWN = 4; constexpr ll DOWNLEFT = 5; constexpr ll LEFT = 6; constexpr ll TOPLEFT = 7; vector> alphabet = { {DOWN, DOWNLEFT}, {DOWN, LEFT}, {DOWN, TOPLEFT}, {DOWN, TOP}, {DOWN, TOPRIGHT}, {DOWN, RIGHT}, {DOWN, DOWNRIGHT}, {DOWNLEFT, LEFT}, {DOWNLEFT, TOPLEFT}, {TOP, RIGHT}, {DOWNLEFT, TOP}, {DOWNLEFT, TOPRIGHT}, {DOWNLEFT, RIGHT}, {DOWNLEFT, DOWNRIGHT}, {LEFT, TOPLEFT}, {LEFT, TOP}, {LEFT, TOPRIGHT}, {LEFT, RIGHT}, {LEFT, DOWNRIGHT}, {TOPLEFT, TOP}, {TOPLEFT, TOPRIGHT}, {TOP, DOWNRIGHT}, {TOPRIGHT, RIGHT}, {TOPRIGHT, DOWNRIGHT}, {TOPLEFT, RIGHT}, {RIGHT, DOWNRIGHT}}; char get_letter(vector> &letter) { vector curr_letter = {letter[1][4], letter[1][7], letter[4][7], letter[7][7], letter[7][4], letter[7][1], letter[4][1], letter[1][1]}; ll first = -1; ll second = -1; for (int i = 0; i < 8; i++) { if (!curr_letter[i]) continue; if (first == -1) { first = i; continue; } else { second = i; break; } } for (int i = 0; i < alphabet.size(); i++) { pair ch = alphabet[i]; if (ch == pair{first, second} || ch == pair{second, first}) return i + 'A'; } assert(false); } vector get_direction(ll dir) { if (dir == TOP) { return { ".........", "....#....", "....#....", "....#....", ".........", ".........", ".........", ".........", "........."}; } else if (dir == TOPRIGHT) { return { ".........", ".......#.", "......#..", ".....#...", ".........", ".........", ".........", ".........", "........."}; } else if (dir == RIGHT) { return { ".........", ".........", ".........", ".........", ".....###.", ".........", ".........", ".........", "........."}; } else if (dir == DOWNRIGHT) { return { ".........", ".........", ".........", ".........", ".........", ".....#...", "......#..", ".......#.", "........."}; } else if (dir == DOWN) { return { ".........", ".........", ".........", ".........", ".........", "....#....", "....#....", "....#....", "........."}; } else if (dir == DOWNLEFT) { return { ".........", ".........", ".........", ".........", ".........", "...#.....", "..#......", ".#.......", "........."}; } else if (dir == LEFT) { return { ".........", ".........", ".........", ".........", ".###.....", ".........", ".........", ".........", "........."}; } else if (dir == TOPLEFT) { return { ".........", ".#.......", "..#......", "...#.....", ".........", ".........", ".........", ".........", "........."}; } assert(false); } vector get_semaphore(char ch) { vector first = get_direction(alphabet[ch - 'A'].first); vector second = get_direction(alphabet[ch - 'A'].second); for (int line = 0; line < first.size(); line++) { for (int col = 0; col < first[line].length(); col++) { if (second[line][col] == '#') first[line][col] = '#'; } } first[4][4] = '*'; return first; } int main() { ll n, c; cin >> n >> c; for (ll i = 0; i < n; i++) { vector> letter; for (ll row = 0; row < 9; row++) { string line; cin >> line; vector bline; for (char ch : line) { bline.push_back(ch != '.'); } letter.push_back(bline); } char curr_letter = get_letter(letter); curr_letter = (curr_letter - 'A' + c) % 26 + 'A'; vector target_letter = get_semaphore(curr_letter); for (ll row = 0; row < target_letter.size(); row++) { cout << target_letter[row] << endl; } } return 0; }