//这是一个数独,我选择用dfs从(1,1)点蛇形搜索下去,到达(9,9)就停止。
//当然有更好的方法,dancing-links
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[10][10],f[4][4][10],ff,lin[10][10],col[10][10];
void dfs(int x,int y)
{
if(ff)return;
if(!a[x][y])
{
for(int i=1;i<=9;i++)
if(!f[(x-1)/3+1][(y-1)/3+1][i])
{
if(lin[x][i]||col[y][i])continue;
if(ff)return;
a[x][y]=i;
lin[x][i]=1;col[y][i]=1;
f[(x-1)/3+1][(y-1)/3+1][i]=1;
if(x==9&&y==9)
{
ff=1;return;
}
if(y%2&&x==9)dfs(x,y+1);
else if(y%2==0&&x==1)dfs(x,y+1);
else if(y%2)dfs(x+1,y);
else dfs(x-1,y);
if(ff)return;
a[x][y]=0;
lin[x][i]=0;col[y][i]=0;
f[(x-1)/3+1][(y-1)/3+1][i]=0;
}
}
else{ if(x==9&&y==9)
{
ff=1;return;
}
if(y%2&&x==9)dfs(x,y+1);
else if(y%2==0&&x==1)dfs(x,y+1);
else if(y%2)dfs(x+1,y);
else dfs(x-1,y);
}
}
int main()
{
//freopen("1.txt","r",stdin);
int T,i,j;
cin>>T;
char s[10];
while(T--)
{
ff=0;
memset(lin,0,sizeof(lin));
memset(col,0,sizeof(col));
memset(f,0,sizeof(f));
for(i=1;i<=9;i++)
{
cin>>s;
for(j=1;j<=9;j++)
{
a[i][j]=s[j-1]-'0';
if(a[i][j])
{
lin[i][a[i][j]]=1;
col[j][a[i][j]]=1;
f[(i-1)/3+1][(j-1)/3+1][a[i][j]]=1;
}
}
}
dfs(1,1);
for(i=1;i<=9;i++)
{for(j=1;j<=9;j++)
cout<<a[i][j]; cout<<endl;}
}
return 0;
}