#include <bits/stdc++.h>
using namespace std;
struct __timestamper {};
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    vector<string> a(9);
    for (int i = 0; i < 9; i++) cin >> a[i];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        if (a[i][j] == '2') {
          a[i][j] = '1';
        }
      }
    }
    for (int i = 0; i < 9; i++) {
      cout << a[i] << endl;
    }
  }
  return 0;
}
