import java.util.*;
public class Main {
static void display(int[][] board) {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
System.out.print(board[i][j]+" ");
}
System.out.println();
}
}
static boolean isItSafeRow(int[][] board, int row, int val) {
for (int c = 0; c < board[0].length; c++) {
if (board[row][c] == val) {
return false;
}
}
return true;
}
static boolean isItSafeCol(int[][] board, int col, int val) {
for (int r = 0; r < board.length; r++) {
if (board[r][col] == val) {
return false;
}
}
return true;
}
static boolean isItSafeBlock(int[][] board, int row, int col, int val) {
int bsr = row - row % 3;
int bsc = col - col % 3;
for (int r = bsr; r < bsr + 3; r++) {
for (int c = bsc; c < bsc + 3; c++) {
if (board[r][c] == val) {
return false;
}
}
}
return true;
}
static boolean isItSafe(int[][] board, int row, int col, int val) {
return isItSafeRow(board, row, val) && isItSafeCol(board, col, val) && isItSafeBlock(board, row, col, val);
}
static void sudukoSolver(int[][] board, int row, int col) {
if (row == board.length) {
display(board);
return;
}
if (col == board[0].length) {
col = 0;
row++;
}
if (board[row][col] != 0) {
sudukoSolver(board, row, col + 1);
return;
}
// place
for (int i = 1; i <= 9; i++) {
if (isItSafe(board, row, col, i)) {
board[row][col] = i;
sudukoSolver(board, row, col + 1);
board[row][col] = 0;
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[][] board = new int[N][N];
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
board[i][j] = sc.nextInt();
}
}
sudukoSolver(board, 0, 0);
}
}