#include <bits/stdc++.h>
using namespace std;
template <class C>
void min_self(C &a, C b) {
  a = min(a, b);
}
template <class C>
void max_self(C &a, C b) {
  a = max(a, b);
}
const long long MOD = 1000000007;
long long mod(long long n, long long m = MOD) {
  n %= m, n += m, n %= m;
  return n;
}
const int MAXN = 1e5 + 5;
const int LOGN = 21;
const long long INF = 1e14;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T1, class T2>
void add(T1 &x, T2 y, long long m = MOD) {
  x += y;
  if (x >= m) x -= m;
}
template <class T1, class T2>
void sub(T1 &x, T2 y, long long m = MOD) {
  x -= y;
  if (x < 0) x += m;
}
char grid[10][10];
void solve() {
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      cin >> grid[i][j];
    }
  }
  auto change = [&](char &x) { x = '0' + mod((x - '0'), 9) + 1; };
  change(grid[0][0]);
  change(grid[3][1]);
  change(grid[6][2]);
  change(grid[1][3]);
  change(grid[4][4]);
  change(grid[7][5]);
  change(grid[2][6]);
  change(grid[5][7]);
  change(grid[8][8]);
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      cout << grid[i][j];
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int test = 1; test <= t; test++) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
