#include <bits/stdc++.h>
using namespace std;
using pi = pair<long long int, long long int>;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    for (long long int i = 0; i < 9; i++) {
      string s;
      cin >> s;
      for (auto ch : s) {
        if (ch == '1') {
          cout << "2";
          continue;
        }
        cout << ch;
      }
      cout << endl;
    }
  }
  return 0;
}
