#include <bits/stdc++.h>
using namespace std;
char Next(char c) { return (c + 1 > '9' ? '1' : c + 1); }
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    vector<string> M;
    for (int i = 0; i < 9; i++) {
      string r;
      cin >> r;
      M.push_back(r);
    }
    M[0][0] = Next(M[0][0]);
    M[1][3] = Next(M[1][3]);
    M[2][6] = Next(M[2][6]);
    M[3][1] = Next(M[3][1]);
    M[4][4] = Next(M[4][4]);
    M[5][8] = Next(M[5][8]);
    M[6][2] = Next(M[6][2]);
    M[7][5] = Next(M[7][5]);
    M[8][7] = Next(M[8][7]);
    for (int i = 0; i < 9; i++) {
      cout << M[i] << "\n";
    }
  }
}
