#include <bits/stdc++.h>
int main() {
  int t, i, j;
  char str[9][9];
  scanf("%d", &t);
  while (t--) {
    for (i = 0; i < 9; i++) scanf("%s", str[i]);
    str[0][0] = str[1][0];
    str[1][3] = str[2][3];
    str[2][6] = str[1][6];
    str[3][1] = str[4][1];
    str[4][4] = str[5][4];
    str[5][7] = str[4][7];
    str[6][2] = str[7][2];
    str[7][5] = str[8][5];
    str[8][8] = str[7][8];
    for (i = 0; i < 9; i++) {
      for (j = 0; j < 9; j++) printf("%c", str[i][j]);
      printf("\n");
    }
  }
  return 0;
}
