#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main() {
  int w[9][9],h[9][9],g[3][3][9],mp[9][9],n,i,j,f=0;
  cin >> n;
  for (n;n>0;n--) {
	  memset(w,0,sizeof(w)); memset(h,0,sizeof(h)); memset(g,0,sizeof(g));
	  for (i=0;i<9;i++) for (j=0;j<9;j++) {
		  cin >> mp[i][j];
		  mp[i][j]--;
          w[j][mp[i][j]]++; h[i][mp[i][j]]++;
		  g[i/3][j/3][mp[i][j]]++;
	  }
	  if (f==0) f=1; else cout << endl;
	  for (i=0;i<9;i++) { 
		  for (j=0;j<9;j++) {
		  if (w[j][mp[i][j]]>1 || h[i][mp[i][j]]>1 || g[i/3][j/3][mp[i][j]]>1) cout << '*'; else cout << ' ';
		  cout << mp[i][j]+1;
	      }
		  cout << endl;
	  }
  }    
    return 0;
}