package work;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class A2676 {
static int T;
static int data[][];
static boolean row[][];
static boolean col[][];
static boolean grid[][];
static boolean flag = false;
public static void main(String[] args) throws FileNotFoundException {
/* Scanner sc=new Scanner(System.in); */
Scanner sc = new Scanner(new File("src/2676.txt"));
T = sc.nextInt();
data = new int[9][9];
row = new boolean[9][11];
col = new boolean[9][10];
grid = new boolean[9][10];
int s;
for (int t = 0; t < T; t++) {
/*
* for (int i = 0; i < 9; i++) { int a = sc.nextInt(); for (int j =
* 8; j > 0; j--) { s = a % 10; a = a / 10; data[i][j] = s;
* row[i][data[i][j]] = 1; col[j][data[i][j]] = 1; grid[i / 3 * 3 +
* j / 3][data[i][j]] = 1; } }
*/
sc.nextLine();
for (int i = 0; i < 9; i++) {
char[] line = sc.nextLine().toCharArray();
for (int j = 0; j < line.length; j++) {
data[i][j] = line[j] - 48;
row[i][data[i][j]] = true;
col[j][data[i][j]] = true;
grid[i / 3 * 3 + j / 3][data[i][j]] = true;
}
}
dfs(0);
if (flag) {
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
System.out.print(data[i][j]);
}
System.out.println();
}
}
}
}
private static void dfs(int step) {
if (step == 81) {
flag = true;
return;
}
int i = step / 9;
int j = step % 9;
if (data[i][j] == 0) {
for (int a = 1; a <= 9; a++) {
if ((row[i][a]) && (col[j][a])
&& (grid[i / 3 * 3 + j / 3][a])) {continue;}
if ((!row[i][a]) && (!col[j][a])
&& (!grid[i / 3 * 3 + j / 3][a])) {
data[i][j] = a;
row[i][a] = true;
col[j][a] = true;
grid[i / 3 * 3 + j / 3][a] = true;
dfs(step + 1);
if (flag)
break;
data[i][j] = 0;
row[i][a] = false;
col[j][a] = false;
grid[i / 3 * 3 + j / 3][a] = false;
}
}
} else {
dfs(step + 1);
}
}
/*
* private static boolean isafe(int p) { for (int i = 0; i < 9; i++) { for
* (int j = 0; j < 9; j++) { if (row[i][p] == 1 || col[j][p] == 1 || grid[i
* / 3 * 3 + j / 3][p] == 1) { return false; } return true; } } return
* false; }
*/
}
//
1
103000509
002109400
000704000
300502006
060000050
700803004
000401000
009205800
804000107
//
143628579
572139468
986754231
391542786
468917352
725863914
237481695
619275843
854396127