#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long a, long long n) {
  if (n == 0) return 1;
  long long p = power(a, n / 2);
  p = (p * p);
  if (n % 2)
    return (p * a);
  else
    return p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    vector<string> v(9);
    for (int i = 0; i < 9; i++) {
      cin >> v[i];
    }
    if (v[0][0] == '1')
      v[0][0] = '2';
    else
      v[0][0] = '1';
    if (v[1][3] == '1')
      v[1][3] = '2';
    else
      v[1][3] = '1';
    if (v[2][6] == '1')
      v[2][6] = '2';
    else
      v[2][6] = '1';
    if (v[3][1] == '1')
      v[3][1] = '2';
    else
      v[3][1] = '1';
    if (v[4][4] == '1')
      v[4][4] = '2';
    else
      v[4][4] = '1';
    if (v[5][7] == '1')
      v[5][7] = '2';
    else
      v[5][7] = '1';
    if (v[6][2] == '1')
      v[6][2] = '2';
    else
      v[6][2] = '1';
    if (v[7][5] == '1')
      v[7][5] = '2';
    else
      v[7][5] = '1';
    if (v[8][8] == '1')
      v[8][8] = '2';
    else
      v[8][8] = '1';
    for (int i = 0; i < 9; i++) cout << v[i] << endl;
    cout << endl;
  }
  return 0;
}
