#include <bits/stdc++.h>
using namespace std;
int a[200005];
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
vector<string> sd;
int main() {
  int t;
  cin >> t;
  while (t--) {
    sd.clear();
    for (int i = 0; i < 9; i++) {
      string tmp;
      cin >> tmp;
      sd.push_back(tmp);
    }
    for (int i = 0; i < 9; i++) {
      sd[0][0] = sd[0][1];
      sd[1][3] = sd[1][4];
      sd[2][6] = sd[2][7];
      sd[3][1] = sd[3][2];
      sd[4][4] = sd[4][5];
      sd[5][7] = sd[5][8];
      sd[6][2] = sd[6][1];
      sd[7][5] = sd[7][4];
      sd[8][8] = sd[8][7];
    }
    for (int i = 0; i < sd.size(); i++) {
      cout << sd[i] << "\n";
    }
  }
  return 0;
}
