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

void main() {
  int n; readf("%d\n", &n);
  for(int t = 0; t < n; t++) {
    int[10][10] w1, w2;
    int[10][3][3] w3;
    int[9][9] field;
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++)
        readf(j == 8 ? "%d\n" : "%d ", &field[i][j]);
    
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++) {
        w1[i][field[i][j]]++;
        w2[j][field[i][j]]++;
        w3[i / 3][j / 3][field[i][j]]++;
      }
    
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++) {
        writef("%s%d%s",
               (w1[i][field[i][j]] != 1 ||
                w2[j][field[i][j]] != 1 ||
                w3[i / 3][j / 3][field[i][j]] != 1) ? "*" : " ",
          field[i][j], j == 8 ? "\n" : "");
      }
    
    if (t != (n - 1)) writeln;
  }
}