#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> sudoko;
  long long t;
  cin >> t;
  while (t--) {
    int n = 9;
    while (n--) {
      string line;
      cin >> line;
      for (auto i : line)
        if (i == '1')
          cout << '2';
        else
          cout << i;
      cout << endl;
    }
  }
}
