#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n;
  cin >> n;
  rep(z, n) {
    if(z) cout << endl;
    ll ch[9][9];
    bool result[9][9];
    rep(i, 9) rep(j, 9) {
      cin >> ch[i][j];
      result[i][j] = false;
    }
    rep(i, 9) rep(j, 9) {
      ll a, b;
      a = ((i + 3) % 3);
      b = ((j + 3) % 3);
      rep(k, j) if(ch[i][j] == ch[i][k]) result[i][j] = result[i][k] = true;
      FOR(k, j + 1, 9) if(ch[i][j] == ch[i][k]) result[i][j] = result[i][k] = true;
      rep(k, i) if(ch[i][j] == ch[k][j]) result[i][j] = result[k][j] = true;
      FOR(k, i + 1, 9) if(ch[i][j] == ch[k][j]) result[i][j] = result[k][j] = true;
      for(int k = (i - a); k < (i - a + 3); k++) {
        for(int l = (j - b); l < (j - b + 3); l++) {
          if(i == k && j == l) continue;
          if(ch[i][j] == ch[k][l]) result[i][j] = result[k][l] = true;
        }
      }
    }
    rep(i, 9) {
      rep(j, 9) {
      if(result[i][j]) cout << '*';
      else cout << ' ';
      cout << ch[i][j];
      }
      cout << endl;
    }
  }
	return 0;
}
