#include <bits/stdc++.h>

using namespace std;

static inline int in(){ int x; scanf("%d", &x); return x; }

int main()
{
  int n = in();
  for (int i = 0; i < n; i++){
    int sudoku[9][9];
    for (int j = 0; j < 9; j++){
      for (int k = 0; k < 9; k++){
        sudoku[j][k] = in() - 1;
      }
    }
    int col[9][9] = {};
    int row[9][9] = {};
    int blk[9][9] = {};
    for (int j = 0; j < 9; j++){
      for (int k = 0; k < 9; k++){
        row[j][sudoku[j][k]]++;
        col[k][sudoku[j][k]]++;
        blk[j/3*3+k/3][sudoku[j][k]]++;
      }
    }
    if (i) puts("");
    for (int j = 0; j < 9; j++){
      for (int k = 0; k < 9; k++){
        if (row[j][sudoku[j][k]] > 1 ||
            col[k][sudoku[j][k]] > 1 ||
            blk[j/3*3+k/3][sudoku[j][k]] > 1){
          printf("*");
        }
        else printf(" ");
        printf("%d", sudoku[j][k] + 1);
      }
      puts("");
    }
  }
  return 0;
}