#include <bits/stdc++.h>
using namespace std;
int multipletest;
const int DEBUGGER = 0;
void solve() {
  int a[9][9];
  for (int i = 0; i < 9; i++) {
    long long x = ({
      int temp;
      cin >> temp;
      temp;
    });
    for (int j = 9 - 1; j >= 0; j--) a[i][j] = x % 10, x /= 10;
  }
  int ix[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}, jx[9] = {0, 3, 6, 1, 4, 7, 2, 5, 8};
  for (int i = 0; i < 9; i++) {
    a[ix[i]][jx[i]] = (a[ix[i]][jx[i]] == 1 ? 2 : 1);
  }
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) cout << a[i][j];
    cout << "" << endl;
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  multipletest = 1;
  if (multipletest) {
    int tc;
    cin >> tc;
    while (tc--) solve();
  } else
    solve();
  return 0;
}
