import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Bear { public static char ALPHABET_SIZE = 26; public static void main(String[] args) { // "SLEEP".chars().forEach(Bear::printChar); // "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().forEach(Bear::printChar); Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int c = scanner.nextInt(); scanner.nextLine(); // read rest of the line int centerX=0; int centerY=0; StringBuilder word = new StringBuilder(); for (int letter = 0; letter < n; letter++) { List rows = new ArrayList<>(); for (int rowI = 0; rowI < 9; rowI++) { String row = scanner.nextLine(); rows.add(row); if(row.contains("*")) { centerY = rowI; centerX = row.indexOf('*'); } } char character = recognizeChar(rows, centerX, centerY); character = (char)('A' + (character - 'A' +c) % ALPHABET_SIZE); word.append(character); } word.chars() .forEach(Bear::printChar); } private static void printChar(int charInt) { char c = (char)charInt; switch (c) { case 'A' -> printCombine(LEFT_DOWN, DOWN); case 'B' -> printCombine(LEFT, DOWN); case 'C' -> printCombine(LEFT_TOP, DOWN); case 'D' -> printCombine(TOP, DOWN); case 'E' -> printCombine(DOWN, TOP_RIGHT); case 'F' -> printCombine(DOWN, RIGHT); case 'G' -> printCombine(DOWN, DOWN_RIGHT); case 'H' -> printCombine(LEFT_DOWN, LEFT); case 'I' -> printCombine(LEFT_DOWN, LEFT_TOP); case 'J' -> printCombine(TOP, RIGHT); case 'K' -> printCombine(LEFT_DOWN, TOP); case 'L' -> printCombine(LEFT_DOWN, TOP_RIGHT); case 'M' -> printCombine(LEFT_DOWN, RIGHT); case 'N' -> printCombine(LEFT_DOWN, DOWN_RIGHT); case 'O' -> printCombine(LEFT, LEFT_TOP); case 'P' -> printCombine(LEFT, TOP); case 'Q' -> printCombine(LEFT, TOP_RIGHT); case 'R' -> printCombine(LEFT, RIGHT); case 'S' -> printCombine(LEFT, DOWN_RIGHT); case 'T' -> printCombine(LEFT_TOP, TOP); case 'U' -> printCombine(LEFT_TOP, TOP_RIGHT); case 'V' -> printCombine(TOP, DOWN_RIGHT); case 'W' -> printCombine(TOP_RIGHT, RIGHT); case 'X' -> printCombine(TOP_RIGHT, DOWN_RIGHT); case 'Y' -> printCombine(LEFT_TOP, RIGHT); case 'Z' -> printCombine(RIGHT, DOWN_RIGHT); default -> System.out.println("ERROR!!!"); } } private static void printCombine(String hand1, String hand2) { for (int y = 0; y < 9; y++) { for (int x = 0; x < 9; x++) { char c1 = hand1.charAt(y * 10 + x); char c2 = hand2.charAt(y * 10 + x); char c; if (c1 == c2) { c = c1; } else { c = '#'; } System.out.print(c); } System.out.println(); } } private static char recognizeChar(List rows, int centerX, int centerY) { char ul = rows.get(centerY-1).charAt(centerX-1); char u = rows.get(centerY-1).charAt(centerX); char ur = rows.get(centerY-1).charAt(centerX+1); char l = rows.get(centerY).charAt(centerX-1); char r = rows.get(centerY).charAt(centerX+1); char dl = rows.get(centerY+1).charAt(centerX-1); char d = rows.get(centerY+1).charAt(centerX); char dr = rows.get(centerY+1).charAt(centerX+1); String flags = ""+ul + u + ur + l + '*' + r + dl + d + dr; char c = switch (flags) { case "....*.##." -> 'A'; case "...#*..#." -> 'B'; case "#...*..#." -> 'C'; case ".#..*..#." -> 'D'; case "..#.*..#." -> 'E'; case "....*#.#." -> 'F'; case "....*..##" -> 'G'; case "...#*.#.." -> 'H'; case "#...*.#.." -> 'I'; case ".#..*#..." -> 'J'; case ".#..*.#.." -> 'K'; case "..#.*.#.." -> 'L'; case "....*##.." -> 'M'; case "....*.#.#" -> 'N'; case "#..#*...." -> 'O'; case ".#.#*...." -> 'P'; case "..##*...." -> 'Q'; case "...#*#..." -> 'R'; case "...#*...#" -> 'S'; case "##..*...." -> 'T'; case "#.#.*...." -> 'U'; case ".#..*...#" -> 'V'; case "..#.*#..." -> 'W'; case "..#.*...#" -> 'X'; case "#...*#..." -> 'Y'; case "....*#..#" -> 'Z'; default -> '?'; }; return c; } public static String DOWN = """ ......... ......... ......... ......... ....*.... ....#.... ....#.... ....#.... ......... """; public static String LEFT_DOWN = """ ......... ......... ......... ......... ....*.... ...#..... ..#...... .#....... ......... """; public static String LEFT = """ ......... ......... ......... ......... .###*.... ......... ......... ......... ......... """; public static String LEFT_TOP = """ ......... .#....... ..#...... ...#..... ....*.... ......... ......... ......... ......... """; public static String TOP = """ ......... ....#.... ....#.... ....#.... ....*.... ......... ......... ......... ......... """; public static String TOP_RIGHT = """ ......... .......#. ......#.. .....#... ....*.... ......... ......... ......... ......... """; public static String RIGHT = """ ......... ......... ......... ......... ....*###. ......... ......... ......... ......... """; public static String DOWN_RIGHT = """ ......... ......... ......... ......... ....*.... .....#... ......#.. .......#. ......... """; }