#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
long long a[10][10];
string s[10];
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, i, j, n, m, l, r, k;
  cin >> t;
  while (t--) {
    for (i = 0; i < 9; i++) {
      cin >> s[i];
    }
    s[1][0] = s[0][0];
    s[0][3] = s[1][3];
    s[2][6] = s[1][6];
    s[3][1] = s[3][0];
    s[4][4] = s[4][3];
    s[5][7] = s[5][6];
    s[6][2] = s[6][0];
    s[7][5] = s[7][3];
    s[8][8] = s[8][6];
    for (i = 0; i < 9; i++) {
      cout << s[i] << "\n";
    }
  }
  return 0;
}
