#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int dx[9]={0,0,0,1,1,1,2,2,2},dy[9]={0,1,2,0,1,2,0,1,2};
int main(){
  int fld[9][9];
  bool num[10],fldb[9][9];
  int n;
  cin>>n;
  for(int times=0;times<n;times++){
    if(times!=0)cout<<endl;
    memset(fldb,true,sizeof(fldb));
    REP(i,9)REP(j,9)cin>>fld[j][i];
    REP(i,9)REP(j,9)REP(k,9)if(fld[i][j]==fld[i][k]&&j!=k)fldb[i][j]=false;
    REP(i,9)REP(j,9)REP(k,9)if(fld[j][i]==fld[k][i]&&j!=k)fldb[j][i]=false;
    REP(i,3)REP(j,3){
      REP(k,9)REP(l,9){
        int nx=i*3,ny=j*3;
        if(fld[nx+dx[k]][ny+dy[k]]==fld[nx+dx[l]][ny+dy[l]]&&k!=l){
          fldb[nx+dx[k]][ny+dy[k]]=false;
        }
      }
    }
    REP(i,9){
      REP(j,9){
        if(fldb[j][i])cout<<" "<<fld[j][i];
        else cout<<"*"<<fld[j][i];
      }
      cout<<endl;
    }
  }
  return 0;
}