#include <bits/stdc++.h>
void solve() {
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      char x;
      std::cin >> x;
      if (x == '9') x = '1';
      std::cout << x;
    }
    std::cout << '\n';
  }
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int t;
  std::cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
