#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int q = 0; q < t; q++) {
    vector<string> s;
    string ss;
    for (int i = 0; i < 9; i++) {
      cin >> ss;
      s.push_back(ss);
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        if (s[i][j] == '1') s[i][j] = '2';
      }
      cout << s[i] << endl;
    }
  }
  return 0;
}
