import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
//TIP To Run code, press or
// click the icon in the gutter.
public class Main {
static int[] dp;
static HashMap abeceda = new HashMap<>();
public static void main(String[] args) {
//TIP Press with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
abeceda.put("A","....*.##.");
abeceda.put("B","...#*..#.");
abeceda.put("C","#...*..#.");
abeceda.put("D",".#..*..#.");
abeceda.put("E","..#.*..#.");
abeceda.put("F","....*#.#.");
abeceda.put("G","....*..##");
abeceda.put("H","...#*.#..");
abeceda.put("I","#...*.#..");
abeceda.put("J",".#..*#...");
abeceda.put("K",".#..*.#..");
abeceda.put("L","..#.*.#..");
abeceda.put("M","....*##..");
abeceda.put("N","....*.#.#");
abeceda.put("O","#..#*....");
abeceda.put("P",".#.#*....");
abeceda.put("Q","..##*....");
abeceda.put("R","...#*#...");
abeceda.put("S","...#*...#");
abeceda.put("T","##..*....");
abeceda.put("U","#.#.*....");
abeceda.put("V",".#..*...#");
abeceda.put("W","..#.*#...");
abeceda.put("X","..#.*...#");
abeceda.put("Y","#...*#...");
abeceda.put("Z","....*#..#");
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
int c =sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String whole = "";
for (int j = 0; j < 9; j++) {
String line = sc.nextLine();
if (j < 6 && j >= 3){
whole += line.substring(3,6);
}
}
var pismenko = "";
for(var a : abeceda.entrySet()){
if (a.getValue().equals(whole)){
pismenko = a.getKey();
break;
}
}
var noveP = pismenko.charAt(0) + c;
if (noveP > 'Z') {
noveP -= 26;
}
var template = abeceda.get(Character.toString(noveP));
var arr = new String[9][9];
System.out.println();
for (int j = 0; j < 9; j++) {
for (int k = 0; k < 9; k++) {
arr[j][k] = ".";
}
}
arr[4][4] = "*";
if (template.charAt(0) == '#') {
arr[1][1] = "#";
arr[2][2] = "#";
arr[3][3] = "#";
}
if (template.charAt(1) == '#') {
arr[3][4] = "#";
arr[2][4] = "#";
arr[1][4] = "#";
}
if (template.charAt(2) == '#') {
arr[3][5] = "#";
arr[2][6] = "#";
arr[1][7] = "#";
}
if (template.charAt(5) == '#') {
arr[4][5] = "#";
arr[4][6] = "#";
arr[4][7] = "#";
}
if (template.charAt(8) == '#') {
arr[5][5] = "#";
arr[6][6] = "#";
arr[7][7] = "#";
}
if (template.charAt(7) == '#') {
arr[5][4] = "#";
arr[6][4] = "#";
arr[7][4] = "#";
}
if (template.charAt(6) == '#') {
arr[5][3] = "#";
arr[6][2] = "#";
arr[7][1] = "#";
}
if (template.charAt(3) == '#') {
arr[4][1] = "#";
arr[4][2] = "#";
arr[4][3] = "#";
}
for (int j = 0; j < 9; j++) {
for (int k = 0; k < 9; k++) {
System.out.print(arr[j][k]);
}
if (j != 8)
System.out.println();
}
}
// int n = sc.nextInt();
// int c = sc.nextInt();
// long sum = 0;
// long min = Integer.MAX_VALUE;
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < c; j++) {
// int l = sc.nextInt();
// sum += l;
// if (min > l && !((i + j) % 2 == 0)) {
// min = l;
// }
// }
// }
// if (n % 2 == 0 && c % 2 == 0) {
// sum -= min;
// }
// System.out.println(sum );
}
static int eating(String current, int count) {
if (current.isEmpty()) {
return count;
}
if (!isPrimeNumber(Long.parseLong(current))) {
return count;
}
count++;
int max = 0;
for (int i = 0; i < current.length(); i++) {
String start = current.substring(0, i);
String end = current.substring(i + 1);
String temp = start + end;
temp = removeZeros(temp);
int countOut = eating(temp, count);
if (countOut > max) {
max = countOut;
}
}
return max;
}
static boolean isPrimeNumber(long n) {
if (n == 1) { return false;}
// if (n == 2 || n == 3 || n == 5) {
// return true;
// }
// if (n % 2 == 0 || n % 3 == 0) {
// return false;
// }
for (int i = 2; i * i <= n; i++) {
// if (n % (i + 1) == 0 || n % (i -1) == 0) {
// return false;
// }
if (n % i == 0) {
return false;
}
}
return true;
}
static String removeZeros(String s){
if (s.isEmpty()) {
return "";
}
if (s.equals("0")) return "";
while(s.charAt(0) == '0'){
s = s.substring(1);
}
return s;
}
// static TreeSet kombinacie = new TreeSet<>();
// public static void uuuu(ArrayList posibilieties, String current)
// {
// if (posibilieties.length == 0 && !kombinacie.contains(current)) {
// kombinacie.add(current);
// return;
// }
// for (int i = 0; i < posibilieties.length; i++) {
// String ss = posibilieties[i] + "";
// var tempcurrent = current + ss;
// var posibilietiesTemp = posibilieties.substring(0, i) + posibilieties.substring(i + 1);
// uuuu(posibilietiesTemp, current);
// }
// }
// public static int findThoughtput(int i)
// {
// int [] array = dp;
// int max = Math.min(array[0], array[1]) + Math.min(array[3], array[4]);
// int abrez = Math.max(0, array[1] - array[0]);
// int derez = Math.max(0, array[4] - array[3]);
// int abvolne = Math.max(0, array[0] - array[1]);
// int devolne = Math.max(0, array[3] - array[4]);
//
// max += Math.max(Math.min(Math.min(abrez, devolne), array[2]), Math.min(Math.min(derez, abvolne), array[2]));
//
// return max;
// }
}