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