#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  map<int, int> m;
  cin >> t;
  while (t--) {
    int a[9][9];
    string str;
    for (int i = 0; i < 9; i++) {
      cin >> str;
      for (int j = 0; j < 9; j++) a[i][j] = str[j] - '0';
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        if ((i == 0 && j == 0) || (i == 1 && j == 3) || (i == 2 && j == 6) ||
            (i == 3 && j == 1) || (i == 4 && j == 4) || (i == 5 && j == 7) ||
            (i == 6 && j == 2) || (i == 7 && j == 5) || (i == 8 && j == 8)) {
          if (a[i][j] == 1)
            cout << "2";
          else
            cout << "1";
        } else
          cout << a[i][j];
      }
      cout << "\n";
    }
  }
}
