#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long hell = round(1e18);
signed solve() {
  long long a[10][10];
  for (long long i = 1; i < 10; i++) {
    for (long long j = 1; j < 10; j++) {
      char ch;
      cin >> ch;
      a[i][j] = ch - '0';
      if ((i == 1 && j == 1) || (i == 4 && j == 2) || (i == 7 && j == 3) ||
          (i == 2 && j == 4) || (i == 5 && j == 5) || (i == 8 && j == 6) ||
          (i == 3 && j == 7) || (i == 6 && j == 8) || (i == 9 && j == 9)) {
        if (a[i][j] == 1)
          a[i][j] = 2;
        else
          a[i][j] = 1;
      }
    }
  }
  for (long long i = 1; i < 10; i++) {
    for (long long j = 1; j < 10; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}
signed main() {
  long long t = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
