#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int arr[9][9];
    for (int i = 0; i < (9); ++i) {
      string s;
      cin >> s;
      for (int j = 0; j < (9); ++j) {
        arr[i][j] = s[j] - '0';
      }
    }
    arr[0][0] = arr[0][1];
    arr[3][1] = arr[3][2];
    arr[6][2] = arr[6][3];
    arr[1][3] = arr[1][4];
    arr[4][4] = arr[4][5];
    arr[7][5] = arr[7][6];
    arr[2][6] = arr[2][7];
    arr[5][7] = arr[5][8];
    arr[8][8] = arr[8][0];
    for (int i = 0; i < (9); ++i) {
      for (int j = 0; j < (9); ++j) {
        cout << arr[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
