#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    vector<string> a(9);
    int n = 9;
    for (int i = 0; i < n; i++) cin >> a[i];
    int x = 0, y = 0;
    int count = 0;
    int f = 0;
    vector<int> c = {0, 1, 2, 3, 4, 5, 6, 7, 8};
    vector<int> d = {0, 3, 6, 1, 4, 7, 2, 5, 8};
    for (int i = 0; i < n; i++) {
      x = c[i];
      y = d[i];
      if (a[x][y] == '9') {
        a[x][y] = '1';
      } else
        a[x][y] = char(int(a[x][y]) + 1);
    }
    for (int i = 0; i < n; i++) {
      cout << a[i] << endl;
    }
  }
  return 0;
}
