#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void debugging(int value) { cerr << value; }
void debugging(long long int value) { cerr << value; }
void debugging(unsigned long long int value) { cerr << value; }
void debugging(double value) { cerr << value; }
void debugging(bool value) { cerr << value; }
void debugging(char value) { cerr << "'" << value << "'"; }
void debugging(string value) { cerr << "\"" << value << "\""; }
template <class T>
void debugging(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    debugging(i);
    cerr << " ";
  }
  cerr << "] ";
}
template <class T>
void debuggingarray(T array, int n) {
  cerr << "[ ";
  for (int i = 0; i < n; i++) {
    debugging(array[i]);
    cerr << " ";
  }
  cerr << "] ";
}
template <class T>
T minftn(T num1, T num2) {
  T num = (num1 < num2) ? (num1) : (num2);
  return num;
}
template <class T>
T maxftn(T num1, T num2) {
  T num = (num1 > num2) ? (num1) : (num2);
  return num;
}
template <class T>
T minarray(T array[], int n) {
  T num = array[0];
  for (int i = 0; i < n; i++) {
    if (array[i] < num) {
      num = array[i];
    }
  }
  return num;
}
template <class T>
T maxarray(T array[], int n) {
  T num = array[0];
  for (int i = 0; i < n; i++) {
    if (array[i] > num) {
      num = array[i];
    }
  }
  return num;
}
template <class T>
T minindex(T array[], int n) {
  T num = array[0];
  int index;
  for (int i = 0; i < n; i++) {
    if (array[i] < num) {
      num = array[i];
      index = i;
    }
  }
  return index;
}
template <class T>
T maxindex(T array[], int n) {
  T num = array[0];
  int index;
  for (int i = 0; i < n; i++) {
    if (array[i] > num) {
      num = array[i];
      index = i;
    }
  }
  return index;
}
template <class T>
T gcdftn(T num1, T num2) {
  if (num1 == num2) {
    return num1;
  } else {
    return gcd(num2, num1 % num2);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s[9];
    for (int i = 0; i < 9; i++) {
      cin >> s[i];
    }
    int a[9][9];
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        a[i][j] = (int)s[i][j] - '0';
        if (a[i][j] == 1) {
          cout << "2";
        } else {
          cout << a[i][j];
        }
      }
      cout << "\n";
    }
  }
  return 0;
}
