#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const long long mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s <= '9' && s >= '0') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
char a[15][15];
int main() {
  long long n, b;
  long long t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < 9; i++) cin >> a[i];
    a[0][0] = a[0][1];
    a[1][3] = a[1][4];
    a[2][6] = a[2][7];
    a[3][1] = a[3][2];
    a[4][4] = a[4][5];
    a[5][7] = a[5][8];
    a[6][2] = a[5][2];
    a[7][5] = a[6][5];
    a[8][8] = a[7][8];
    for (int i = 0; i < 9; i++) cout << a[i] << endl;
  }
}
