#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  int b, c;
  cin >> b;
  while (b--) {
    for (int j = 0; j < 9; j++) {
      cin >> a;
      for (int i = 0; i < 9; i++) {
        if (a[i] == '2') {
          cout << 1;
        } else
          cout << a[i];
      }
      cout << endl;
    }
  }
  return 0;
}
