//刚开始没有出来的原因是存储的下标没有控制好 做题脑子不清楚
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int heng[10][10];
int zong[10][10];
int squa[10][10];
int pos[10][10]={
0,0,0,0,0,0,0,0,0,0,
0,1,1,1,2,2,2,3,3,3,
0,1,1,1,2,2,2,3,3,3,
0,1,1,1,2,2,2,3,3,3,
0,4,4,4,5,5,5,6,6,6,
0,4,4,4,5,5,5,6,6,6,
0,4,4,4,5,5,5,6,6,6,
0,7,7,7,8,8,8,9,9,9,
0,7,7,7,8,8,8,9,9,9,
0,7,7,7,8,8,8,9,9,9,};
int sq[10][10];
int x,m;
int dfs(int x,int y)
{
if(x==10)
return 1;
bool flag;
if(sq[x][y])
{
if(y == 9) flag = dfs(x+1,1);
else flag = dfs(x,y+1);
if(flag) return 1;
else return 0;
}
else{
for(int i=1;i<=9;i++)
{
if(!heng[x][i] && !zong[y][i] && !squa[pos[x][y]][i])
{
sq[x][y] = i;
heng[x][i] = 1;
zong[y][i] = 1;
squa[pos[x][y]][i] = 1;
if(y==9) flag = dfs(x+1,1);
else flag = dfs(x,y+1);
if(flag) return 1;
else
{
sq[x][y] = 0; //第一次忘了这句
heng[x][i] = 0; //回溯过程很重要
zong[y][i] = 0;
squa[pos[x][y]][i] = 0;
//return 0; 没有必要 我们要继续进行下面的for循环
}
}
}
}
return 0;
}
int main()
{
scanf("%d",&m);
while(m--)
{
x=0;
memset(heng,0,10*10);
memset(zong,0,10*10);
memset(squa,0,10*10);
char ch[10];
for(int i=1;i<=9;i++)
{
scanf("%s",ch);
for(int j=0;j<9;j++)
{
x = ch[j]-'0';
heng[i][x] = 1;
zong[j+1][x] = 1;
squa[pos[i][j+1]][x]=1;
sq[i][j+1]=x; //这里第一次出现错误
}
}
dfs(1,1);
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
printf("%d",sq[i][j]);
}
printf("\n");
}
}
return 0;
}