#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    string s[9];
    for (int i = 0; i < 9; i++) {
      cin >> s[i];
      for (int j = 0; j < 9; j++) {
        if (s[i][j] == '9') {
          x = i / 3 + 1;
          s[i][j] = '0' + x;
        }
      }
    }
    for (int i = 0; i < 9; i++) cout << s[i] << endl;
  }
}
