#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    char grid[10][10];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cin >> grid[i][j];
      }
    }
    int x = 0;
    for (int i = 0; i < 9; i += 3) {
      int cnt = 0;
      for (int j = x; j < 9; j += 3) {
        if (grid[i + cnt][j] == '1') {
          grid[i + cnt][j] = '2';
        } else {
          grid[i + cnt][j] = '1';
        }
        cnt += 1;
      }
      x += 1;
    }
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cout << grid[i][j];
      }
      cout << endl;
    }
  }
}
