#include <bits/stdc++.h>
using namespace std;
int change(int x) {
  x++;
  if (x == 10) x = 1;
  return x;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int arr[9][9], chk[3] = {};
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        char ch;
        cin >> ch;
        arr[i][j] = ch - '0';
      }
    }
    arr[0][0] = change(arr[0][0]);
    arr[1][3] = change(arr[1][3]);
    arr[2][6] = change(arr[2][6]);
    arr[3][1] = change(arr[3][1]);
    arr[4][4] = change(arr[4][4]);
    arr[5][7] = change(arr[5][7]);
    arr[6][2] = change(arr[6][2]);
    arr[7][5] = change(arr[7][5]);
    arr[8][8] = change(arr[8][8]);
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) cout << arr[i][j];
      cout << endl;
    }
  }
  return 0;
}
