#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int OO = 1e9;
int n;
string second[9];
int d[] = {0, 3, 6, 1, 4, 7, 2, 5, 8};
void solve(int a, int b) {
  for (int i = 1; i <= 9; ++i) {
    if (i + '0' != second[a][b]) {
      second[a][b] = i + '0';
      return;
    }
  }
}
void init() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    for (int i = 0; i < 9; ++i) {
      cin >> second[i];
      solve(i, d[i]);
      cout << second[i] << '\n';
    }
  }
  return 0;
}
