#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  cin.ignore();
  while (t--) {
    vector<string> grid(9);
    for (int i = 0; i < 9; i++) getline(cin, grid[i]);
    int cnty = 0;
    for (int i = 0; i < 8; i++) {
      if (grid[i][cnty] == '5')
        grid[i][cnty] = '9';
      else
        grid[i][cnty] = '5';
      cnty = (cnty + 3) % 8;
    }
    if (grid[8][8] == '5')
      grid[8][8] = '9';
    else
      grid[8][8] = '5';
    for (auto e : grid) cout << e << '\n';
  }
  return 0;
}
