#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 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){
      memset(num,false,sizeof(num));
      REP(j,9)if(num[fld[i][j]]){
        int l=fld[i][j];
        REP(k,9)if(fld[i][k]==l)fldb[i][k]=false;
      }else num[fld[i][j]]=true;
    }
    REP(i,9){
      memset(num,false,sizeof(num));
      REP(j,9)if(num[fld[j][i]]){
        int l=fld[j][i];
        REP(k,9)if(fld[k][i]==l)fldb[k][i]=false;
      }else num[fld[j][i]]=true;
    }
    REP(i,3)REP(j,3){
      memset(num,false,sizeof(num));
      REP(x,3)REP(y,3){
        int nx=i*3+x,ny=j*3+y;
        if(num[fld[nx][ny]]){
          REP(o,3)REP(p,3)if(fld[o][p]==fld[nx][ny])fldb[o][p]=false;
        }else num[fld[nx][ny]]=true;
      }
    }
    REP(i,9){
      REP(j,9){
        if(fldb[j][i])cout<<" "<<fld[j][i];
        else cout<<"*"<<fld[j][i];
      }
      cout<<endl;
    }
  }
  return 0;
}