#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n;

  cin >> n;

  int pazzle[n][9][9];
  
  int point[n][9][9];
  
  //point={0}
  for(int i = 0;i < n;++i){
    for(int j = 0;j < 9;++j){
      for(int k = 0;k < 9;++k){
	point[i][j][k] = 0;
      }
    }
  }
			     
  
  //scan
  for(int i = 0;i < n;++i){
    for(int j = 0;j < 9;j++){
      for(int k = 0;k < 9;k++){
	cin >> pazzle[i][j][k];
      }
    }
  }

  //syori
  for(int i = 0;i < n;i++){
    for(int j = 0;j < 9;j++){
      for(int k = 0;k < 9;k++){
	for(int l = 0;l < 9;l++){
	  //tate
	  if(pazzle[i][j][k] == pazzle[i][j][l] && k != l){
	    point[i][j][k] = 1;
	    point[i][j][l] = 1;
	  }
	  //yoko
	  if(pazzle[i][l][j] == pazzle[i][k][j] && k != l){
	    point[i][l][j] = 1;
	    point[i][k][j] = 1;
	  }
	}
      }
      //masu
      switch(j){
	
      case 0:{
	for(int a = 0;a < 3;a++){
	  for(int b = 0;b < 3;b++){
	    for(int c = 0;c < 3;c++){
	      for(int d = 0;d < 3;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 1:{
	for(int a = 0;a < 3;a++){
	  for(int b = 3;b < 6;b++){
	    for(int c = 0;c < 3;c++){
	      for(int d = 3;d < 6;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 2:{
	for(int a = 0;a < 3;a++){
	  for(int b = 6;b < 9;b++){
	    for(int c = 0;c < 3;c++){
	      for(int d = 6;d < 9;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 3:{
	for(int a = 3;a < 6;a++){
	  for(int b = 0;b < 3;b++){
	    for(int c = 3;c < 6;c++){
	      for(int d = 0;d < 3;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 4:{
	for(int a = 3;a < 6;a++){
	  for(int b = 3;b < 6;b++){
	    for(int c = 3;c < 6;c++){
	      for(int d = 3;d < 6;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 5:{
	for(int a = 3;a < 6;a++){
	  for(int b = 6;b < 9;b++){
	    for(int c = 3;c < 6;c++){
	      for(int d = 6;d < 9;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d)){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 6:{
	for(int a = 6;a < 9;a++){
	  for(int b = 0;b < 3;b++){
	    for(int c = 6;c < 9;c++){
	      for(int d = 0;d < 3;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 7:{
	for(int a = 6;a < 9;a++){
	  for(int b = 3;b < 6;b++){
	    for(int c = 6;c < 9;c++){
	      for(int d = 3;d < 6;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }

      case 8:{
	for(int a = 6;a < 9;a++){
	  for(int b = 6;b < 9;b++){
	    for(int c = 6;c < 9;c++){
	      for(int d = 6;d < 9;d++){
		if(pazzle[i][a][b] == pazzle[i][c][d] && (a != c && b != d) ){
		  point[i][a][b] = 1;
		  point[i][c][d] = 1;
		  break;
		}
	      }
	    }
	  }
	}
      }
      }
    }
  }      

  //print
  for(int i = 0;i < n;i++){
    for(int j = 0;j < 9;j++){
      for(int k = 0;k < 9;k++){
	if(!point[i][j][k]){
	  cout << " " << pazzle[i][j][k];
	}
	else{
	  cout << "*" << pazzle[i][j][k];
	}
      }
      cout << endl;
    }
    if(i < n-1)cout << endl;
  }
}

Measured memory_bytes: 1176