#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int c[9][9];
int data[9][9];


void check_1(){
  int appear[10];
  for(int i = 0; i < 9; i++){
    fill(appear,appear+10,0);
    for(int j = 0; j < 9; j++)
      appear[data[i][j]]++;
    for(int k = 0; k < 9; k++)
      if(appear[data[i][k]] > 1) c[i][k] = 1; 
  }
}

void check_2(){
  int appear[10];
  for(int i = 0; i < 9; i++){
    fill(appear,appear+10,0);
    for(int j = 0; j < 9; j++)
      appear[data[j][i]]++;
    for(int k = 0; k < 9; k++)
      if(appear[data[k][i]] > 1) c[k][i] = 1; 
  }
}

void check_3(){
  int appear[10];
  
  for(int STx = 0; STx < 9; STx+=3)
    for(int STy = 0; STy < 9; STy+=3){
      fill(appear,appear+10,0);
      for(int i = STx; i < STx+3; i++)
	for(int j = STy; j < STy+3; j++)
	  appear[data[i][j]]++;

      for(int i = STx; i < STx+3; i++)
	for(int j = STy; j < STy+3; j++)
	  if(appear[data[i][j]] > 1) c[i][j] = 1;
    }    
}

void print(){
  for(int i = 0; i < 9; i++){
    for(int j = 0; j < 9; j++){
      if(c[i][j]) cout << "*";
      else cout << " ";
      cout << data[i][j];
    }
    cout << endl;
  }
}

int main(){

  int num;
  cin >> num;
  for(int rev = 0; rev < num; rev++){
    if(rev) cout << endl;
    memset(c,0,sizeof(c));
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++)
	cin >> data[i][j];
    
    check_1();
    check_2();
    check_3();
    print();
  }
  return 0; 
}