#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int sudoku[9][9];
    int size = 0;
    while (size < 9) {
      long long int number;
      cin >> number;
      for (int i = 8; i > -1; i--) {
        sudoku[size][i] = number % 10;
        number = number / 10;
      }
      size++;
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        if (sudoku[i][j] == 2) {
          sudoku[i][j] = 6;
          break;
        }
      }
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cout << sudoku[i][j];
      }
      cout << endl;
    }
  }
}
