/***********************************************/
/*                                             */
/* Author Hilmi Yildirim, Graduate Student RPI */
/*                                             */
/***********************************************/
#include<stdio.h>
//#define inputfilename "graphIn.txt"
//#define outputfilename "graphOut.txt"
#define MAXB 10

int B;
int graph[MAXB*MAXB][MAXB*MAXB];
int digitList[3][MAXB*MAXB][MAXB*MAXB+1];

void put(int no, int px, int py)
{
  graph[px][py] = no;
  digitList[0][px][no] = 1;
  digitList[1][py][no] = 1;
  digitList[2][(px/3)*3+ py/3][no] = 1;
}

void delete(int no, int px, int py)
{
  graph[px][py] = 0;
  digitList[0][px][no] = 0;
  digitList[1][py][no] = 0;
  digitList[2][(px/3)*3+ py/3][no] = 0;
}

int suitable(int no, int px, int py)
{
  return !digitList[0][px][no] && !digitList[1][py][no] && !digitList[2][(px/3)*3+ py/3][no];
}

void printGraph()
{
  int i,j;
  //FILE *f = fopen(outputfilename,"w");
  for(i=0; i<B*B; i++,printf("\n"))
    for(j=0; j<B*B; j++)
      printf("%d ",graph[i][j]);
  //fclose(f);
}

void readInitialGraph()
{
  int i,j;
  //FILE *f = fopen(inputfilename, "r");
  scanf("%d",&B);
  for(i=0; i<B*B; i++)
    for(j=0; j<B*B; j++){
      scanf(" %d",&graph[i][j]);
      if(graph[i][j])
	put(graph[i][j],i,j);
    }
  //fclose(f);
  printGraph();
  printf("************************\n");
}


void find_sol(int si,int sj)
{
  int i;
  int x = si, y = sj;
  while(x<B*B){
    while(y<B*B){
      if(!graph[x][y])
	{
	  for(i = 1;i<=B*B; i++)
	    if(suitable(i,x,y)){
	      put(i,x,y);
	      find_sol(x,y);
	      delete(i,x,y);
	    }
	  return;
	}
      y++;
    }
    x++;
    y=0;
  }
  if(x == B*B){
    printGraph();
    exit(0);
  }
}
int main(){
  readInitialGraph();
  find_sol(0,0);
}
