#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  for (int tt = 0; tt < t; tt++) {
    vector<vector<int> > A(9, vector<int>(9));
    for (int i = 0; i < 9; i++) {
      int q;
      scanf("%d", &q);
      for (int j = 0; j < 9; j++) {
        A[i][8 - j] = q % 10;
        q /= 10;
      }
    }
    A[0][0] = A[0][1];
    A[1][3] = A[0][3];
    A[2][6] = A[0][6];
    A[3][1] = A[3][0];
    A[4][4] = A[3][4];
    A[5][7] = A[4][7];
    A[6][2] = A[6][1];
    A[7][5] = A[8][5];
    A[8][8] = A[7][7];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) printf("%d", A[i][j]);
      printf("\n");
    }
  }
  return 0;
}
