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