#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  char a[9][9];
  while (q--) {
    for (int i = 0; i < 9; i++)
      for (int j = 0; j < 9; j++) cin >> a[i][j];
    if (a[0][0] != '9')
      a[0][0] = '9';
    else
      a[0][0] = '1';
    if (a[3][1] != '9')
      a[3][1] = '9';
    else
      a[3][1] = '1';
    if (a[6][2] != '9')
      a[6][2] = '9';
    else
      a[6][2] = '1';
    if (a[1][3] != '9')
      a[1][3] = '9';
    else
      a[1][3] = '1';
    if (a[4][4] != '9')
      a[4][4] = '9';
    else
      a[4][4] = '1';
    if (a[7][5] != '9')
      a[7][5] = '9';
    else
      a[7][5] = '1';
    if (a[2][6] != '9')
      a[2][6] = '9';
    else
      a[2][6] = '1';
    if (a[5][7] != '9')
      a[5][7] = '9';
    else
      a[5][7] = '1';
    if (a[8][8] != '9')
      a[8][8] = '9';
    else
      a[8][8] = '1';
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) cout << a[i][j];
      cout << endl;
    }
  }
}
