#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test_case;
  cin >> test_case;
  while (test_case--) {
    char a[9][9];
    for (long long int i = 0; i < 9; i++) {
      for (long long int j = 0; j < 9; j++) {
        cin >> a[i][j];
        if (a[i][j] == '1') {
          a[i][j] = '2';
        }
      }
    }
    for (long long int i = 0; i < 9; i++) {
      for (long long int j = 0; j < 9; j++) {
        cout << a[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
