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