#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc, n = 9;
  char str[10];
  scanf("%d", &tc);
  while (tc--) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (i % 3 == 0) cnt = i / 3;
      scanf("%s", str);
      if (str[cnt] == '9')
        str[cnt] = str[cnt] - 1;
      else
        str[cnt] = str[cnt] + 1;
      printf("%s\n", str);
      cnt = cnt + 3;
    }
  }
  return 0;
}
