#include<bits/stdc++.h>
using namespace std;
char str[82], a[9][9];
bool row[9][10], col[9][10], bck[9][10], ok=0, haveans=0;
int block(int r, int c) {
return (r/3)*3+c/3;
}
bool check(int r, int c, int val) {
return !row[r][val] && !col[c][val] && !bck[block(r, c)][val];
}
void dfs(int dep, int r, int c) {
if(ok) return;
if(dep>9*9) {
ok=1;
for(int i=0; i<9; i++) {
for(int j=0; j<9; j++)
cout<<a[i][j];
}
cout<<endl;
return;
}
int nr, nc;
if(c==8)
nr=r+1, nc=0;
else
nr=r, nc=c+1;
if(a[r][c]!='0') {
dfs(dep+1, nr, nc);
} else {
for(int i=1; i<=9; i++) {
if(check(r, c, i)) {
a[r][c]=i+'0';
row[r][i]=true;
col[c][i]=true;
bck[block(r, c)][i]=true;
dfs(dep+1, nr, nc);
a[r][c]='0';
row[r][i]=false;
col[c][i]=false;
bck[block(r, c)][i]=false;
}
}
}
}
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", str);
memset(row, 0, sizeof row);
memset(col, 0, sizeof col);
memset(bck, 0, sizeof bck);
for(int i=0; i<9; i++) {
for(int j=0; j<9; j++) {
if (str[i*9+j] == '0') {
a[i][j] = '0';
} else {
a[i][j] = str[i*9+j];
row[i][a[i][j]-'0']=true;
col[j][a[i][j]-'0']=true;
bck[block(i, j)][a[i][j]-'0']=true;
}
}
}
ok=0;
dfs(1,0,0);
}
return 0;
}
/*
2
005000600080701040700060003090205060008040900060109080500090002040308010006000700
005000600080701040700060003090205060008040900060109080500090002040308010006000700
*/