#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a[9][9];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        char c;
        cin >> c;
        a[i][j] = c - '0';
      }
    }
    for (int i = 0; i < 9; i += 3) {
      int k = i / 3, x, cnt[10];
      memset(cnt, 0, sizeof(cnt));
      bool b = false;
      for (x = 1;; x++) {
        b = true;
        for (int j = i; j < i + 3; j++) {
          if (a[j][(j - i) * 3 + k] == x) {
            b = false;
            break;
          }
        }
        if (b) {
          break;
        }
      }
      for (int j = 0; j < 3; j++) {
        a[i + j][j * 3 + k] = x;
      }
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cout << a[i][j];
      }
      cout << '\n';
    }
  }
  return 0;
}
