#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#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()
#define mp make_pair
#define pb push_back
#define f first
#define s second


main(){
  int n;
  cin>>n;
  while(n--){
    map<int,int> masu[9],tate[9],yoko[9];
    int puz[9][9];
    rep(i,9)rep(j,9){
      cin>>puz[i][j];
      masu[i/3*3+j/3][puz[i][j]]++;
      tate[i][puz[i][j]]++;
      yoko[j][puz[i][j]]++;
    }

    rep(i,9){
      rep(j,9){
        if(masu[i/3*3+j/3][puz[i][j]]>1 || tate[i][puz[i][j]]>1 || yoko[j][puz[i][j]]>1)cout<<"*";
        else cout<<" ";
        cout<<puz[i][j];
      }
      cout<<endl;
    }
    if(n)cout<<endl;
  }
}