#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    vector<string> v;
    for (int i = 0; i < 9; i++) {
      string x;
      cin >> x;
      v.push_back(x);
    }
    v[0][0] = v[0][1];
    v[1][3] = v[1][4];
    v[2][6] = v[2][7];
    v[3][1] = v[3][2];
    v[4][4] = v[4][5];
    v[5][7] = v[5][8];
    v[6][2] = v[6][3];
    v[7][5] = v[7][6];
    v[8][8] = v[8][7];
    for (int i = 0; i < v.size(); i++) {
      cout << v[i] << "\n";
    }
  }
  return 0;
}
