#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace std;
void solve() {
  string str;
  int arr[9][9];
  for (int i = 0; i < 9; ++i) {
    cin >> str;
    for (int j = 0; j < 9; ++j) arr[i][j] = str[j] - '0';
  }
  for (int i = 0; i < 9; ++i) {
    for (int j = 0; j < 9; ++j) cout << (arr[i][j] == 2 ? 1 : arr[i][j]);
    cout << "\n";
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
