#include <bits/stdc++.h>
using namespace std;
const long long MOD = 666013;
char ch[10][10];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, a, b, i, j;
    for (i = 1; i <= 9; i++) {
      for (j = 1; j <= 9; j++) {
        cin >> ch[i][j];
      }
    }
    int c = 1;
    for (i = 1; i <= 9; i += 3) {
      int k = i;
      for (j = c; j <= 9; j += 3) {
        if (ch[k][j] != '1')
          ch[k][j] = (ch[k][j] - '1') - 1 + '1';
        else
          ch[k][j] = '2';
        k++;
      }
      c++;
    }
    for (i = 1; i <= 9; i++) {
      for (j = 1; j <= 9; j++) {
        cout << ch[i][j];
      }
      cout << "\n";
    }
  }
  return 0;
}
