#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  int n = 9;
  vector<vector<char>> v(n, vector<char>(n));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) cin >> v[i][j];
  for (int i = 0; i < 9; i += 3) {
    for (int j = 0; j < 9; j += 3) {
      if (v[i + (j / 3)][(j + (i / 3)) % 9] != '1')
        v[i + (j / 3)][(j + (i / 3)) % 9] = '1';
      else
        v[i + (j / 3)][(j + (i / 3)) % 9] = '2';
    }
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (9); j++) cout << v[i][j];
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  cin >> q;
  while (q--) {
    solve();
    cout << '\n';
  }
}
