#include <bits/stdc++.h>
using namespace std;
void solve() {
  vector<string> a(9);
  for (int i = (int)(0); i < (int)(9); i++) cin >> a[i];
  for (int i = (int)(0); i < (int)(9); i++)
    for (int j = (int)(0); j < (int)(9); j++)
      a[i][j] == '2' ? a[i][j] = '1' : a[i][j] = a[i][j];
  for (int i = (int)(0); i < (int)(9); i++) {
    for (int j = (int)(0); j < (int)(9); j++) cout << a[i][j];
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt;
  cin >> tt;
  while (tt--) solve();
}
