#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
const int N = (int)1e5 + 10;
void TimeExecution() {
  cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    string s[10];
    for (int i = (1); i <= (9); i++) cin >> s[i];
    s[1][0] = s[1][1];
    s[2][3] = s[2][4];
    s[3][6] = s[3][7];
    s[4][1] = s[4][2];
    s[5][4] = s[5][5];
    s[6][7] = s[6][8];
    s[7][2] = s[7][3];
    s[8][5] = s[8][6];
    s[9][8] = s[9][7];
    for (int i = (1); i <= (9); i++) cout << s[i] << endl;
  }
  return 0;
}
