#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int grid[9][9];
  int n;
  cin>>n;
  bool fst = false;
  while(n--){
    if(fst){
      cout<<endl;
    }else{
      fst = true;
    }
    REP(y,9)REP(x,9)cin>>grid[y][x];
    REP(y,9){
      REP(x,9){
        bool f=false;
        int bx = x-x%3;
        int by = y-y%3;
        REP(sx,9){
          if(x==sx) continue;
          if(grid[y][x]==grid[y][sx]) f = true;
        }
        REP(sy,9){
          if(y==sy) continue;
          if(grid[y][x]==grid[sy][x]) f = true;
        }
        REP(dy,3)REP(dx,3){
          if(by+dy==y&&bx+dx==x) continue;
          if(grid[y][x]==grid[by+dy][bx+dx]) f=true;
        }
        if(f) cout<<"*";
        else cout<<" ";
        cout<<grid[y][x];
      }
      cout<<endl;
    }
  }
  return 0;
}