#include <iostream>
#include <cstring>
using namespace std;
int m[9][9][2];
int main()
{
  int n,i,j,k,l;
  bool f = false;
  cin >> n;
  while(n--){
    memset(m,0,sizeof(m));
    if(f) cout << endl;
    for(i=0;i<9;i++){
      for(j=0;j<9;j++){
	cin >> k;
	m[i][j][0] = k;
	for(k=0;k<i;k++){
	  if(m[i][j][0] == m[k][j][0]){
	    m[i][j][1] = 1;
	    m[k][j][1] = 1;
	  }
	}
	for(k=0;k<j;k++){
	  if(m[i][j][0] == m[i][k][0]){
	    m[i][j][1] = 1;
	    m[i][k][1] = 1;
	  }
	}
	for(k=(i/3)*3; k<=i; k++){
	  for(l=(j/3)*3; l<((k==i) ? j:((j/3)*3+2)); l++){
	    if(m[i][j][0] == m[k][l][0]){
	      m[i][j][1] = 1;
	      m[k][l][1] = 1;
	    }
	  }
	}
      }
    }
    for(i=0;i<9;i++){
      for(j=0;j<9;j++){
	if(m[i][j][1] == 1) cout << "*";
	else cout << " ";
	cout << m[i][j][0];
      }
      cout << endl;
    }
    f = true;
  }
  return 0;
}