#include<iostream>
using namespace std;
int main(){
  int n;
  int mapp[9][9];
  int koteiyoko,koteitate;
  cin>>n;
  for(int mawa=0;mawa<n;mawa++){
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cin>>mapp[i][j];
      }
    }
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	koteiyoko=mapp[i][j];
	koteitate=mapp[j][i];
	for(int k=0;k<9;k++){
	  if(koteiyoko==mapp[i][k] && k!=j){
	    mapp[i][k]=mapp[i][k]+10;
	    mapp[i][j]=mapp[i][j]+10;
	  }
	  if(koteitate==mapp[k][i] && k!=j){
	    mapp[k][i]=mapp[k][i]+10;
	    mapp[j][i]=mapp[j][i]+10;
	  }
	}
      }
    }
    
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	if(mapp[i][j]>=10){
	  cout<<'*'<<mapp[i][j]%10;
	}else{
	  cout<<' '<<mapp[i][j];
	}
      }
      cout<<endl;
    }
  }
}