#include <bits/stdc++.h>
using namespace std;
char x[20][20], num;
int i;
int main() {
  cin >> i;
  while (i--) {
    num = '9';
    for (int k = 1; k <= 9; k++)
      for (int j = 1; j <= 9; j++) {
        cin >> x[k][j];
      }
    x[1][1] = x[1][2];
    x[4][2] = x[4][3];
    x[7][3] = x[7][4];
    x[2][4] = x[2][5];
    x[5][5] = x[5][6];
    x[8][6] = x[8][7];
    x[3][7] = x[3][8];
    x[6][8] = x[6][9];
    x[9][9] = x[8][9];
    for (int k = 1; k <= 9; k++) {
      for (int j = 1; j <= 9; j++) {
        cout << x[k][j];
      }
      cout << endl;
    }
  }
  return 0;
}
