#include <bits/stdc++.h>
using namespace std;
int grid[9][9];
int main() {
  int t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < 9; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < 9; j++) {
        grid[i][j] = s[j] - '0';
      }
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        int y = 3 * i + j, x = 3 * j + i;
        if (grid[x][y] == 1)
          grid[x][y] = 2;
        else
          grid[x][y] = 1;
      }
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) cout << grid[i][j];
      cout << "\n";
    }
  }
  return 0;
}
