#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point() {}
  point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T power(T n, T p) {
  T res = 1;
  for (int i = 0; i < p; i++) res *= n;
  return res;
}
template <class T>
double getdist(T a, T b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
  stringstream ss(s);
  ss >> ret;
  return ret;
}
template <class T>
string tostring(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
struct fast {
  fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
} cincout;
char s[10][10];
vector<pair<int, int>> v{{1, 1}, {2, 4}, {3, 7}, {4, 2}, {5, 5},
                         {6, 8}, {7, 3}, {8, 6}, {9, 9}};
bool rec(int indx) {
  if (indx == (int)(v.size())) return true;
  for (int i = 0; i < 9; i++) {
    auto x = v[indx];
    if (i == s[x.first][x.second] - '1') continue;
    char old = s[x.first][x.second];
    s[x.first][x.second] = i + '1';
    if (rec(indx + 1)) return true;
    s[x.first][x.second] = old;
  }
  return false;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    for (int i = 1; i <= 9; i++)
      for (int j = 1; j <= 9; j++) cin >> s[i][j];
    assert(rec(0) == true);
    for (int i = 1; i < 10; i++) {
      for (int j = 1; j < 10; j++) cout << s[i][j];
      cout << "\n";
    }
  }
  return 0;
}
