#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  bool error[10][10];
  int puzzle[10][10];
  
  int T;
  cin >> T;
  while(T--){
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cin >> puzzle[i][j];
      }
    }
    
    memset(error, 0, sizeof(error));
    int check1[10];
    int check2[10];
    
    for(int i = 0 ; i < 9 ; i++){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int j = 0 ; j < 9 ; j++){
	check1[puzzle[i][j]]++;
	check2[puzzle[j][i]]++;
	
	if(check1[puzzle[i][j]] >= 2){
	  error[i][j] = 1;
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[i][k] == puzzle[i][j]) error[i][k] = 1;
	  }
	}
	  
	if(check2[puzzle[j][i]] >= 2){
	  error[j][i] = 1;
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[k][i] == puzzle[j][i]) error[k][i] = 1;
	  }
	}
	
      }
    }
    
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cout << ((error[i][j]) ? '*' : ' ') << puzzle[i][j];
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}