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