#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;


int main(){
  int n; cin>>n;
  int cc = 0;
  while(n --> 0){
    int  b[9][9];
    bool f[9][9];
    if(cc++ != 0) puts("");
    REP(i,9) REP(j,9){
      cin>>b[i][j];
      f[i][j] = true;
    }
    for(int y = 0; y<9; y+=3){
      for(int x = 0; x<9; x+=3){
        int cnt[10] = {0};
        REP(i,3) REP(j,3)
          cnt[b[y+i][x+j]]++;
        REP(i,3) REP(j,3)
          if(cnt[b[y+i][x+j]] != 1){
            f[y+i][x+j] = false;
          }
      }
    }
    REP(y,9){
      int cnt[10] = {0};
      REP(x,9)
        cnt[b[y][x]]++;
      REP(x,9)
        if(cnt[b[y][x]] != 1)
          f[y][x] = false;
    }
    REP(x,9){
      int cnt[10] = {0};
      REP(y,9)
        cnt[b[y][x]]++;
      REP(y,9)
        if(cnt[b[y][x]] != 1)
          f[y][x] = false;
    }

    REP(i,9){
      REP(j,9)
        printf("%c%d",(f[i][j]?' ':'*'),b[i][j]);
      puts("");
    }
  }
  return 0;
}