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

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
int p[10][10];
bool f[10][10];
using namespace std;
 
void ck(int x, int y){
  rep(i, 9){
    if(i != x && p[i][y] == p[x][y]) f[i][y] = f[x][y] = 1;
    if(i != y && p[x][i] == p[x][y]) f[x][i] = f[x][y] = 1;
  }
  FOR(i, 3 * (x / 3), 3 * ((x / 3) + 1)) FOR(j, 3 * (y / 3), 3 * ((y / 3)+1)){
    if(i == x && j == y) continue;
    if(p[i][j] == p[x][y])
      f[i][j] = f[x][y] = 1;
  }
} 
                        
int main(){
  int n;
  scanf("%d", &n);
  rep(i, n){
    if(i != 0) puts("");
    rep(i, 9) rep(j, 9) f[j][i] = 0;
    rep(i, 9) rep(j, 9)
      scanf("%d", &p[i][j]);
 
    rep(i, 9){
      rep(j, 9){
    ck(i, j);
    printf(f[i][j] ? "*":" ");
    printf("%d", p[i][j]);
      }
      puts("");
    }
  }
  return 0;
}