#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int field[9][9] = {0};
    bool flag[9][9] = {false};
    for(int i=0; i<9; i++){
      for(int j=0; j<9; j++){
	cin >>field[i][j];
      }
    }
    for(int i=0; i<9; i++){
      int log[10] = {0};
      for(int j=0; j<9; j++){
	if(log[field[i][j]] != 0){flag[i][j] = true;flag[i][log[field[i][j]]-1] = true;}
	log[field[i][j]] = j+1;
      }
    }
    for(int i=0; i<9; i++){
      int log[10] = {0};
      for(int j=0; j<9; j++){
	if(log[field[j][i]] != 0){flag[j][i] = true;flag[log[field[j][i]]-1][i] = true;}
	log[field[j][i]] = j+1;
      }
    }
    for(int i=0; i<9; i++){
      int log[10] = {0};
      for(int j=0; j<9; j++){
	if(log[field[j%3+(i%3)*3][j/3+(i/3)*3]] != 0){
	  int r = log[field[j%3+(i%3)*3][j/3+(i/3)*3]]-1;
	  flag[j%3+(i%3)*3][j/3+(i/3)*3] = true;
	  flag[r%3+(i%3)*3][r/3+(i/3)*3] = true;
	}
	log[field[j%3+(i%3)*3][j/3+(i/3)*3]] = j+1;
      }
    }
    for(int i=0; i<9; i++){
      for(int j=0; j<9; j++){
	if(flag[i][j]){cout <<"*";}
	else{cout <<" ";}
	cout <<field[i][j];
      }
      cout <<endl;
    }
  }
  return 0;
}