#include <iostream>

#include <cstdio>
#include <cstring>
#include <ctime>

using namespace std;

int main(){

  int n;

  cin >> n;

  int puzzle[n][9][9];
  bool cpuzzle[n][9][9];
  
  // Init flag
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 9; j++){
      for(int k = 0; k < 9; k++){
	cpuzzle[i][j][k] = false;
      }
    }
  }    

  // Loop
  for(int i = 0; i < n; i++){
    // Input
    for(int j = 0; j < 9; j++){
      for(int k = 0; k < 9; k++){
	cin >> puzzle[i][j][k];
      }
    }
    // Check
    for(int j = 0; j < 9; j++){
      for(int k = 0; k < 9; k++){
	// Check line1
	for(int l1 = 0; l1 < 9; l1++){
	  if(l1 != k){
	    if(puzzle[i][j][k] == puzzle[i][j][l1]){
	      cpuzzle[i][j][k] = true;
	    }
	  }
	}
	// Check line2
	for(int l2 = 0; l2 < 9; l2++){
	  if(l2 != j){
	    if(puzzle[i][j][k] == puzzle[i][l2][k]){
	      cpuzzle[i][j][k] = true;
	    }
	  }
	}
	// Check area
	for(int a1 = 0; a1 < 3; a1++){
	  for(int a2 = 0; a2 < 3; a2++){
	    // Area1
	    if(j >= 0 && j <= 2 && k >= 0 && k <= 2){
	      if(a1 != j && a2 != k){
		if(puzzle[i][j][k] == puzzle[i][a1][a2]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area2
	    if(j >= 3 && j <= 5 && k >= 0 && k <= 2){
	      if(a1+3 != j && a2 != k){
		if(puzzle[i][j][k] == puzzle[i][a1+3][a2]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area3
	    if(j >= 6 && j <= 8 && k >= 0 && k <= 2){
	      if(a1+6 != j && a2 != k){
		if(puzzle[i][j][k] == puzzle[i][a1+6][a2]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area4
	    if(j >= 0 && j <= 2 && k >= 3 && k <= 5){
	      if(a1 != j && a2+3 != k){
		if(puzzle[i][j][k] == puzzle[i][a1][a2+3]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area5
	    if(j >= 3 && j <= 5 && k >= 3 && k <= 5){
	      if(a1+3 != j && a2+3 != k){
		if(puzzle[i][j][k] == puzzle[i][a1+3][a2+3]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area6
	    if(j >= 6 && j <= 8 && k >= 3 && k <= 5 ){
	      if(a1+6 != j && a2+3 != k){
		if(puzzle[i][j][k] == puzzle[i][a1+6][a2+3]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area7
	    if(j >= 0 && j <= 2 && k >= 6 && k <= 8){
	      if(a1 != j && a2+6 != k){
		if(puzzle[i][j][k] == puzzle[i][a1][a2+6]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area8
	    if(j >= 3 && j <= 5 && k >= 6 && k <= 8){
	      if(a1+3 != j && a2+6 != k){
		if(puzzle[i][j][k] == puzzle[i][a1+3][a2+6]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	    // Area9
	    if(j >= 6 && j <= 8 && k >= 6 && k <= 8){
	      if(a1+6 != j && a2+6 != k){
		if(puzzle[i][j][k] == puzzle[i][a1+6][a2+6]){
		  cpuzzle[i][j][k] = true;
		}
	      }
	    }
	  }
	}
      }
    }
    // Output
    for(int j = 0; j < 9; j++){
      for(int k = 0; k < 9; k++){
	if(cpuzzle[i][j][k]){
	  cout << "*";
	} else {
	  cout << " ";
	}
	cout << puzzle[i][j][k];
      }
      cout << endl;
    }
    if(i < n-1)cout << endl;
  }
  
  return 0;
}