#include<cstdio>
#define z c[x][y]
#define w c[90+x][z]
#define v c[180+y][z]
#define q c[270+y/3*3+x/3][z]
#define d(a,c)for(a=0;a<c;a++)
#define h d(y,9){d(x,9)
#define a return
#define s scanf("%d",&z)
int c[360][10],x,y;int f(int x,int y){if(z)a x<8?f(x+1,y):y&8?1:f(0,y+1);d(z,10)if(!(v|w|q)){v=w=q=1;if(f(x,y))a 1;v=w=q=0;}z=0;a 0;}int main(){s;h{s;v=w=q=1;}}f(0,0);h{printf("%d ",z);}printf("\n");}}