#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string out = "", line;
    for (int i = 9; i--;) {
      cin >> line;
      line[line.find('2')] = '1';
      out += line + '\n';
    }
    cout << out;
  }
  return 0;
}
