#include <bits/stdc++.h>
using namespace std;
const long long maxx = 1e5 + 5;
void ZeoN() {
  long long t, i, j, k, m, n, x, y, z, a, b, c, d, p;
  double xx, yy, zz;
  char cc, temp;
  string s, s1;
  cin >> t;
  while (t--) {
    for (i = 0; i < 9; i++) {
      cin >> s;
      for (j = 0; j < 9; j++) {
        if (s[j] == '2')
          cout << "3";
        else
          cout << s[j];
      }
      cout << endl;
    }
  }
}
signed main() {
  long long test = 1;
  while (test--) {
    ZeoN();
  }
  return 0;
}
