#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int a[9][9];
bool f[9][9];
int main(){
  int n;
  cin>>n;
  while(n--){
    r(i,9)r(j,9){cin>>a[i][j];f[i][j]=false;}
    int c[10];
    r(i,9){memset(c,0,sizeof(c));r(j,9)c[a[i][j]]++;
      r(j,9)if(1<c[a[i][j]])f[i][j]=true;
    }
    r(j,9){memset(c,0,sizeof(c));r(i,9)c[a[i][j]]++;
      r(i,9)if(1<c[a[i][j]])f[i][j]=true;
    }
    for(int y=0;y<9;y+=3)for(int x=0;x<9;x+=3){
      memset(c,0,sizeof(c));
      r(i,3)r(j,3)c[a[y+i][x+j]]++;
      r(i,3)r(j,3)if(1<c[a[y+i][x+j]])f[y+i][x+j]=true;
    }
    r(i,9){r(j,9){
      if(f[i][j])cout<<'*';
      else cout<<' ';
      cout<<a[i][j];
    }
    cout<<endl;
  }
  if(n)cout<<endl;
}
}