#include <bits/stdc++.h>
using namespace std;
int v[20][20];
bool c[20];
bool r[20];
void solve() {
  memset(c, false, sizeof(c));
  memset(r, false, sizeof(r));
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      char a;
      cin >> a;
      v[i][j] = (a - '0');
    }
  }
  for (int i = 1; i <= 3; i++) {
    for (int j = 1 + 3 * (i - 1); j <= (3 + 3 * (i - 1)); j++) {
      if (!c[j]) {
        c[j] = true;
        for (int z = 1; z <= 9; z++) {
          if (v[i][j] != z) {
            v[i][j] = z;
            break;
          }
        }
        break;
      }
    }
  }
  for (int i = 4; i <= 6; i++) {
    for (int j = 1 + 3 * (i - 4); j <= (3 + 3 * (i - 4)); j++) {
      if (!c[j]) {
        c[j] = true;
        for (int z = 1; z <= 9; z++) {
          if (v[i][j] != z) {
            v[i][j] = z;
            break;
          }
        }
        break;
      }
    }
  }
  for (int i = 7; i <= 9; i++) {
    for (int j = 1 + 3 * (i - 7); j <= (3 + 3 * (i - 7)); j++) {
      if (!c[j]) {
        c[j] = true;
        for (int z = 1; z <= 9; z++) {
          if (v[i][j] != z) {
            v[i][j] = z;
            break;
          }
        }
        break;
      }
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      cout << v[i][j];
    }
    cout << '\n';
  }
}
int32_t main() {
  long long t = 1;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
}
