#include <bits/stdc++.h>
using namespace std;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    vector<string> v;
    for (int i = 0; i < 9; i++) {
      string s;
      cin >> s;
      v.push_back(s);
    }
    v[0][0] = v[1][0];
    v[3][1] = v[4][1];
    v[6][2] = v[7][2];
    v[1][3] = v[2][3];
    v[4][4] = v[5][4];
    v[7][5] = v[7][4];
    v[2][6] = v[1][6];
    v[5][7] = v[4][7];
    v[8][8] = v[7][8];
    for (int i = 0; i < 9; i++) {
      cout << v[i] << endl;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
