#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 4;
int32_t main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    char in[9][9];
    for (long long i = 0; i < 9; i++) {
      for (long long j = 0; j < 9; j++) {
        cin >> in[i][j];
      }
    }
    long long arr[9][9];
    for (long long i = 0; i < 9; i++) {
      for (long long j = 0; j < 9; j++) {
        arr[i][j] = in[i][j] - '0';
      }
    }
    arr[0][0] += 1;
    if (arr[0][0] == 10) {
      arr[0][0] = 1;
    }
    arr[1][3] += 1;
    if (arr[1][3] == 10) {
      arr[1][3] = 1;
    }
    arr[2][6] += 1;
    if (arr[2][6] == 10) {
      arr[2][6] = 1;
    }
    arr[3][1] += 1;
    if (arr[3][1] == 10) {
      arr[3][1] = 1;
    }
    arr[4][4] += 1;
    if (arr[4][4] == 10) {
      arr[4][4] = 1;
    }
    arr[5][7] += 1;
    if (arr[5][7] == 10) {
      arr[5][7] = 1;
    }
    arr[6][2] += 1;
    if (arr[6][2] == 10) {
      arr[6][2] = 1;
    }
    arr[7][5] += 1;
    if (arr[7][5] == 10) {
      arr[7][5] = 1;
    }
    arr[8][8] += 1;
    if (arr[8][8] == 10) {
      arr[8][8] = 1;
    }
    for (long long i = 0; i < 9; i++) {
      for (long long j = 0; j < 9; j++) {
        cout << arr[i][j];
      }
      cout << "\n";
    }
  }
}
