#include <bits/stdc++.h>
using namespace std;
void test();
string s;
int main() {
  for (int i = 0; i < 26; ++i) {
    s += (char)('a' + i);
  }
  ios_base::sync_with_stdio(false);
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    test();
    cout << endl;
  }
  return 0;
}
void test() {
  string s[9];
  for (int i = 0; i < 9; ++i) {
    cin >> s[i];
  }
  int j = 0;
  for (int i = 0; i < 9; ++i) {
    if (i % 3 == 0 && i > 0) j++;
    s[i][j] = (s[i][j] == '1' ? '2' : '1');
    j = (j + 3) % 9;
  }
  for (int i = 0; i < 9; ++i) {
    cout << s[i] << endl;
  }
}
