#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  char grid[9][9];
  while (t--) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cin >> grid[i][j];
        grid[i][j] = grid[i][j] == '1' ? '2' : grid[i][j];
      }
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) cout << grid[i][j];
      cout << endl;
    }
  }
  return 0;
}
