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