#include <bits/stdc++.h>
using namespace std;
long long findx(long long a) {
  long long x = 0, v = 0;
  while (v < a) {
    v = ((1LL) << (x - 1));
    if (v >= a) return x;
    x++;
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    vector<vector<int>> arr;
    for (int i = 0; i < 9; i++) {
      long long a;
      cin >> a;
      vector<int> h;
      while (a) {
        h.push_back(a % 10);
        a /= 10;
      }
      reverse(h.begin(), h.end());
      arr.push_back(h);
    }
    int t = arr[0][0];
    arr[0][0] = arr[1][0];
    arr[1][3] = arr[2][3];
    arr[2][6] = arr[0][6];
    arr[3][1] = arr[4][1];
    arr[4][4] = arr[5][4];
    arr[5][7] = arr[3][7];
    arr[6][2] = arr[7][2];
    arr[7][5] = arr[8][5];
    arr[8][8] = arr[6][8];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cout << arr[i][j];
      }
      cout << endl;
    }
  }
}
