#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int T;
  cin >> T;
  while (T--) {
    string s[9];
    for (long long int i = 0; i < 9; i++) {
      cin >> s[i];
    }
    for (long long int i = 0; i < 9; i++) {
      for (long long int j = 0; j < 9; j++) {
        if (s[i][j] == '3') s[i][j] = '1';
      }
    }
    for (long long int i = 0; i < 9; i++) {
      cout << s[i] << "\n";
    }
  }
  return 0;
}
