#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
char fek(long long n) {
  if (n == 9) {
    return '1';
  } else {
    return char('0' + n + 1);
  }
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long t;
  cin >> t;
  for (long long _ = 0; _ < (long long)t; ++_) {
    vector<string> a(9);
    for (long long i = 0; i < (long long)9; ++i) {
      cin >> a[i];
    }
    a[0][0] = fek(a[0][0] - '0');
    a[1][3] = fek(a[1][3] - '0');
    a[2][6] = fek(a[2][6] - '0');
    a[3][1] = fek(a[3][1] - '0');
    a[4][4] = fek(a[4][4] - '0');
    a[5][7] = fek(a[5][7] - '0');
    a[6][2] = fek(a[6][2] - '0');
    a[7][5] = fek(a[7][5] - '0');
    a[8][8] = fek(a[8][8] - '0');
    for (long long i = 0; i < (long long)9; ++i) {
      cout << a[i] << endl;
    }
    cout << endl;
  }
  return 0;
}
