#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 6;
const int mod = 1e9 + 7;
char s[10][10];
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    for (int i = 1; i <= 9; i++) scanf("%s", s[i] + 1);
    int cnt = 1;
    for (int i = 1; i <= 9; i++) {
      s[i][cnt] = s[i][cnt] < '9' ? s[i][cnt] + 1 : s[i][cnt] - 1;
      cnt += 3;
      if (cnt > 9) cnt -= 8;
    }
    for (int i = 1; i <= 9; i++) printf("%s\n", s[i] + 1);
  }
  return 0;
}
