import java.io.BufferedInputStream;
import java.util.Scanner;
public class TEST {
static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) {
int n = sc.nextInt();
String[] mn = new String[9];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 9; j++) {
mn[j % 3 * 3 + j / 3] = sc.next();
}
for (int j = 0; j < 9; j++) {
if (j % 3 == 2) {
System.out.println(mn[j]);
} else {
System.out.print(mn[j] + " ");
}
}
}
}
}
import java.util.Scanner;
public class TEST {
static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) {
int n = sc.nextInt();
String[] mn = new String[9];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 9; j++) {
mn[j % 3 * 3 + j / 3] = sc.next();
}
for (int j = 0; j < 9; j++) {
if (j % 3 == 2) {
System.out.println(mn[j]);
} else {
System.out.print(mn[j] + " ");
}
}
}
}
}