#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d%*c", &t);
  while (t--) {
    for (int i = 1; i <= 9; i++) {
      for (int j = 1; j <= 9; j++) {
        char c = getchar();
        if (c == '9')
          putchar('1');
        else
          putchar(c);
      }
      getchar(), puts("");
    }
  }
  return 0;
}
