#include<bits/stdc++.h>
using namespace std;

int n;
int board[9][9];
int dxy[3][3] = { { 0, 1, 2},
		  {-1, 0, 1},
		  {-2,-1, 0} };

bool cheak(int y,int x){
  for(int i=0;i<9;i++){
    if(i != y && board[y][x] == board[i][x]) return true;
    if(i != x && board[y][x] == board[y][i]) return true;
  }
  int py = y % 3;
  int px = x % 3;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      int nx = x+dxy[px][i];
      int ny = y+dxy[py][j];
      if(nx == x && ny == y) continue;
      if(board[y][x] == board[ny][nx]) return true;
    }
  }
  return false;
}

int main(){
  cin >> n;
  while(n--){
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cin >> board[i][j];
      }
    }
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	if(cheak(i,j)) cout << "*" << board[i][j];
	else cout << " " << board[i][j];
      }
      cout << endl;
    }
  }
}