#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    int i, j;
    for (i = 0; i < 9; i++) {
      string s;
      cin >> s;
      for (j = 0; j < 9; j++) {
        if (s[j] == '1') s[j] = '2';
      }
      cout << s << endl;
    }
  }
}
