#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < 9; i++) {
      string s;
      cin >> s;
      s.replace(s.find("1"), 1, "2");
      cout << s << endl;
    }
  }
}
