#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < 9; i++) {
      string a;
      cin >> a;
      for (int i = 0; i < 9; i++) {
        if (a[i] == '5') {
          a[i] = '6';
        }
      }
      cout << a << "\n";
    }
  }
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  return 0;
}
