
import std.stdio, std.string, std.algorithm, std.conv, std.array;

void main() {
  int times; readf("%d\n", &times);
  for(int t = 0; t < times; t++) {
    int col, row;
    int[10][10] wrong1, wrong2;
    int[10][3][3] wrong3;
    int[][] field;

    for(int i = 0; i < 9; i++) {
      field ~= readln.chomp.split(" ").map!(to!int).array;
    }
  
    for(int i = 0; i < 9; i++) {
      for(int j = 0; j < 9; j++) {
        wrong1[i][field[i][j]]++;
        wrong2[j][field[i][j]]++;
        wrong3[i / 3][j / 3][field[i][j]]++;
      }
    }

    for(int i = 0; i < 9; i++) {
      for(int j = 0; j < 9; j++) {
        bool result = (wrong1[i][field[i][j]] != 1 ||
                       wrong2[j][field[i][j]] != 1 ||
                       wrong3[i / 3][j / 3][field[i][j]] != 1);
        writef("%s%d%s",  result ? "*" : " ", field[i][j], j == 8 ? "\n" : "");
      }
    }
    if (t != (times - 1)) writeln;
  }
}