#include<iostream>
#include<vector>

using namespace std;

int main(void){
  int n ;
  cin>>n;
  while(n--){
    vector<vector<char> > in(9,vector<char>(9));
    vector<vector<bool> > ans(9,vector<bool>(9,false));
    vector<vector<int> > usedx(9,vector<int>(9,-1));
    vector<vector<int> > usedy(9,vector<int>(9,-1));
    vector<vector<int> > usedz(9,vector<int>(9,-1));

    for(int i = 0 ; i < 9 ; i ++){
      for(int j = 0 ; j < 9 ; j ++){

	cin>>in[i][j];
	in[i][j] = in[i][j] - '1';
	
	if(usedx[i][in[i][j]] == -1){
	  usedx[i][in[i][j]] = j;
	}else{
	  ans[i][j] = true;
	  ans[i][usedx[i][in[i][j]]] = true ;
	}

	if(usedy[in[i][j]][j] == -1){
	  usedy[in[i][j]][j] = i;
	}else{
	  ans[i][j] = true;
	  ans[usedy[in[i][j]][j]][j] = true;
	}
	
	//cout<<(int)in[i][j]<<" "<<i<<" "<<j<<" "<<i/3*3+j/3<<endl;
	if(usedz[i/3*3+j/3][in[i][j]] == -1){
	  usedz[i/3*3+j/3][in[i][j]] = i*10+j;
	}else{
	  ans[i][j] = true;
	  ans[usedz[i/3*3+j/3][in[i][j]]/10][usedz[i/3*3+j/3][in[i][j]]%10] = true;
	}
      }
    }
    
    for(int i = 0 ; i < 9 ; i ++){
      for(int j = 0 ; j < 9 ; j ++){
	if(ans[i][j])cout<<"*";
	else cout<<" ";
	cout<<(int)in[i][j]+1<<" ";
      }
      cout<<endl;
    }
    cout<<endl;
  }
}