#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    vector<string> v(9);
    for (int i = 0; i < 9; i++) cin >> v[i];
    int p, pp = 0;
    for (int i = 0; i < 9; i++) {
      if (i % 3 == 0) p = pp++;
      for (int j = 0; j < 9; j++) {
        if (v[i][p] - '0' != j + 1) {
          v[i][p] = j + 1 + '0';
          break;
        }
      }
      p = (p + 3) % 9;
    }
    for (int i = 0; i < 9; i++) cout << v[i] << endl;
  }
}
