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

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};

//////////////////////////////////////////////////////////////


int main() {
  
  int Tc; cin >> Tc;
  int grid[9][9];
  char output[9][19];
  bool bl = 0;
  while(Tc--) {
    if(bl) cout << endl;
    bl = 1;
    rep(i,9) output[i][18] = 0;
    
    rep(i,9)rep(j,9) cin >> grid[i][j];
    rep(i,9)rep(j,9) {
      output[i][2*j]   = ' ';
      output[i][2*j+1] = static_cast<char>('0' + grid[i][j]);
    }
    
    rep(i,9) {
      set<int> used, star;
      rep(j,9) {
	if(used.count(grid[i][j])) {
	  star.insert(grid[i][j]);
	}
	used.insert(grid[i][j]);
      }
      rep(j,9) {
	if(star.count(grid[i][j])) {
	  output[i][2*j] = '*';
	}
      }
    }
    
    rep(j,9) {
      set<int> used, star;
      rep(i,9) {
	if(used.count(grid[i][j])) {
	  star.insert(grid[i][j]);
	}
	used.insert(grid[i][j]);
      }
      rep(i,9) {
	if(star.count(grid[i][j])) {
	  output[i][2*j] = '*';
	}
      }
    }
    
    rep(i,3) {
      rep(j,3) {
	set<int> used, star;
	rep(k,3) {
	  rep(l,3) {
	    if(used.count(grid[i*3+k][j*3+l])) {
	      star.insert(grid[i*3+k][j*3+l]);
	    }
	    used.insert(grid[i*3+k][j*3+l]);
	  }
	}
	rep(k,3) {
	  rep(l,3) {
	    if(star.count(grid[i*3+k][j*3+l])) {
	      output[i*3+k][2*(j*3+l)] = '*';
	    }
	  }
	}
      }
    }
    
    rep(i,9) {
      cout << output[i] << endl;
    }
    
  }
  
  return 0;
}