#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    char ara[9][9];
    for (int j = 0; j < 9; j++) {
      for (int k = 0; k < 9; k++) {
        cin >> ara[j][k];
      }
    }
    cout << endl;
    int j;
    int k = 0;
    for (j = 0; j <= 2; j++) {
      ara[j][k + 1] = ara[j][k];
      k = k + 3;
    }
    k = 1;
    for (j = 3; j <= 5; j++) {
      ara[j][k + 1] = ara[j][k];
      k = k + 3;
    }
    k = 1;
    for (j = 6; j <= 8; j++) {
      ara[j][k - 1] = ara[j][k];
      k = k + 3;
    }
    for (int j = 0; j < 9; j++) {
      for (int k = 0; k < 9; k++) {
        cout << ara[j][k];
      }
      cout << "\n";
    }
  }
}
