#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long _power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long invmod(long long a, long long m) { return _power(a, m - 2, m); }
void sieve(long long n, vector<bool> &prime) {
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long arr[9][9];
    for (long long i = 0; i <= 8; i++) {
      for (long long j = 0; j <= 8; j++) {
        char a;
        cin >> a;
        arr[i][j] = a - '0';
      }
    }
    arr[0][0] = arr[0][0] % 9 + 1;
    arr[1][3] = arr[1][3] % 9 + 1;
    arr[2][6] = arr[2][6] % 9 + 1;
    arr[3][1] = arr[3][1] % 9 + 1;
    arr[4][4] = arr[4][4] % 9 + 1;
    arr[5][7] = arr[5][7] % 9 + 1;
    arr[6][2] = arr[6][2] % 9 + 1;
    arr[7][5] = arr[7][5] % 9 + 1;
    arr[8][8] = arr[8][8] % 9 + 1;
    for (long long i = 0; i <= 8; i++) {
      for (long long j = 0; j <= 8; j++) cout << arr[i][j];
      cout << "\n";
      ;
    }
  }
}
