#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n = 9;
    vector<string> sud(n);
    for (long long i = 0; i < n; i++) cin >> sud[i];
    char c;
    for (long long i = 0; i < 9; i += 3) {
      long long p = i, v, s = i / 3;
      for (long long j = s; j < 9; j += 3) {
        c = sud[p][j];
        v = c - '0';
        v = v - 1;
        if (v == 0) v = 9;
        sud[p][j] = v + '0';
        p++;
      }
    }
    for (long long i = 0; i < n; i++) cout << sud[i] << "\n";
  }
}
