#include <bits/stdc++.h>
#pragma GCC optimize("O2")
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
using namespace std;
const int maxn = 1000 * 100 + 5;
const long long inf = 9223372036854775807;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    string s[9];
    for (int i = 0; i < 9; i++) {
      cin >> s[i];
    }
    s[1][0] = s[0][0];
    s[0][4] = s[0][3];
    s[2][7] = s[2][6];
    s[3][2] = s[3][1];
    s[4][3] = s[3][3];
    s[5][6] = s[5][7];
    s[7][1] = s[6][1];
    s[6][5] = s[6][4];
    s[8][8] = s[8][7];
    for (int i = 0; i < 9; i++) {
      cout << s[i] << endl;
    }
  }
}
