#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){
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[i][k] == puzzle[i][j]) error[i][k] = true;
	  }
	}
	
	if(check2[puzzle[j][i]] >= 2){
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[k][i] == puzzle[j][i]) error[k][i] = true;
	  }
	}
	
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int i = k ; i < k+3 ; i++){
	for(int j = 0 ; j < 3 ; j++){
	  check1[puzzle[i][j]]++;
	  if(check1[puzzle[i][j]] >= 2){
	    for(int _i = k ; _i < k+3 ; _i++){
	      for(int _j = 0 ; _j < 3 ; _j++){
		if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
	      }
	    }
	  }
	}
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int i = k ; i < k+3 ; i++){
	for(int j = 3 ; j < 6 ; j++){
	  check1[puzzle[i][j]]++;
	  if(check1[puzzle[i][j]] >= 2){
	    for(int _i = k ; _i < k+3 ; _i++){
	      for(int _j = 3 ; _j < 6 ; _j++){
		if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
	      }
	    }
	  }
	}
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int i = k ; i < k+3 ; i++){
	for(int j = 6 ; j < 9 ; j++){
	  check1[puzzle[i][j]]++;
	  if(check1[puzzle[i][j]] >= 2){
	    for(int _i = k ; _i < k+3 ; _i++){
	      for(int _j = 6 ; _j < 9 ; _j++){
		if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
	      }
	    }
	  }
	}
      }
    }
	
    
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cout << ((error[i][j]) ? '*' : ' ') << puzzle[i][j];
      }
      cout << endl;
    }
    if(T)cout << endl;
  }
  return 0;
}

      