#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    char arr[9][9];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cin >> arr[i][j];
        if (arr[i][j] == '2') arr[i][j] = '9';
        cout << arr[i][j];
      }
      cout << "\n";
    }
  }
}
