#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,i,j,k,l,m,a,b;
  int number[10][10];
  bool wrong[10][10];//wrong??????true*
  int check[10]={};
 
  cin>>n;

  rep(i,n){
    if(i)cout<<endl;
    rep(j,9)rep(k,9){
      wrong[j][k]=false;
      scanf("%d",&number[j][k]);
    }

    rep(j,9){//yoko check
      rep(k,10)
	check[k]=0;//0??§?????????
      rep(k,9){
	check[number[j][k]]++;
	if(check[number[j][k]]>1){//2nd
	  rep(l,9)
	    if(number[j][l]==number[j][k])
	      wrong[j][l]=true;
	    
	}
      }//repk
    }//repj
    

    rep(k,9){//tate check
      rep(j,10)
	check[k]=0;//?????????
      rep(j,8){
	for(l=j+1;l<9;l++)
	  if(number[j][k]==number[l][k]){
	    wrong[j][k]=true;
	    wrong[l][k]=true;
	  }
      }//repj
    }//repk
    
    rep(j,3){//block check
      rep(k,3){
	rep(l,10)
	  check[l]=0;//?????????
	rep(l,3)
	  rep(m,3){
	  check[number[3*j+l][3*k+m]]++;
	  if(check[number[3*j+l][3*k+m]]>1){//2nd
	    rep(a,3)
	      rep(b,3)
	      if(number[3*j+a][3*k+b]==number[3*j+l][3*k+m])
		wrong[3*j+a][3*k+b]=true;
	      
	  }
	}
      }//repk
    }//repj

    rep(j,9){
      rep(k,9){
	if(wrong[j][k])
	  cout<<"*";
	else 
	  cout<<" ";
	cout<<number[j][k];
      }
      cout<<endl;
    }


 
  }
}