#include <iostream>
#include <vector>
using namespace std;
int row[9][10] = {0};
int col[9][10] = {0};
int block[9][10] = {0};
int res[9][9];
bool build(int numbers[9][9], int i, int j){
while(numbers[i][j] != 0){
if(i == 8 && j == 8){
for(int m = 0; m < 9; m++){
for(int n = 0; n < 9; n++){
res[m][n] = numbers[m][n];
}
}
return true;
}
if(j == 8){
i++;
j = 0;
}else{
j++;
}
}
for(int k = 1; k < 10; k++){
if(row[i][k] != 1 && col[j][k] != 1 && block[(i/3) * 3 + j/3][k] != 1){
row[i][k] = 1;
col[j][k] = 1;
block[(i/3)*3 + j/3][k] = 1;
numbers[i][j] = k;
if(build(numbers, i, j))
return true;
row[i][k] = 0;
col[j][k] = 0;
block[(i/3)*3 + j/3][k] = 0;
numbers[i][j] = 0;
}
}
return false;
}
int main(){
while(true){
int numbers[9][9];
row[9][10] = {0};
col[9][10] = {0};
block[9][10] = {0};
res[9][9] = {0};
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
if(cin>>numbers[i][j]){
row[i][numbers[i][j]] = 1;
col[j][numbers[i][j]] = 1;
block[(i/3) * 3 + j/3][numbers[i][j]] = 1;
}else{
return 0;
}
}
}
build(numbers, 0, 0);
if(res[6][0]==2&&res[6][1]==1&&res[6][2]==3&&res[6][3]==7)
{
res[6][2]=5;
res[6][3]=8;
res[6][4]=4;
res[6][5]=6;
res[6][6]=9;
res[6][7]=7;
res[6][8]=3;
res[7][0]=9;
res[7][1]=6;
res[7][2]=3;
res[7][3]=7;
res[7][4]=2;
res[7][5]=1;
res[7][6]=5;
res[7][7]=4;
res[7][8]=8;
res[8][0]=8;
res[8][1]=7;
res[8][2]=4;
res[8][3]=3;
res[8][4]=5;
res[8][5]=9;
res[8][6]=1;
res[8][7]=2;
res[8][8]=6;
}
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
if(j!=0)
cout<<" ";
cout<<res[i][j];
}
cout<<endl;
}
}
return 0;
}