#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int tests = 0; tests < t; tests++) {
    string grid[9];
    for (int i = 0; i < 9; i++) {
      cin >> grid[i];
    }
    int ov = 0;
    for (int j = 0; j < 3; j++) {
      for (int a = 0; a < 3; a++) {
        if (grid[ov][j + a * 3] == '1') {
          grid[ov][j + a * 3] = '2';
        } else {
          grid[ov][j + a * 3] = '1';
        }
        ov++;
      }
    }
    for (int i = 0; i < 9; i++) {
      cout << grid[i] << endl;
      ;
    }
  }
  return 0;
}
