#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 9;
const int W = 9;

int main() {
  int T; cin >>T;
  bool ff = false;
  REP(t, T){
    if(ff) cout <<endl; ff = true;
    int v[H][W];
    REP(i, H) REP(j, W) cin >>v[i][j];
    bool f[H][W];
    memset(f, 0, sizeof(f));

    REP(i, H) REP(j, W) FOR(k, j + 1, W) if(v[i][j] == v[i][k]) f[i][j] = f[i][k] = true;
    REP(i, W) REP(j, H) FOR(k, j + 1, H) if(v[j][i] == v[k][i]) f[j][i] = f[k][i] = true;
    REP(i, 9){
      int y = (i / 3) * 3, x = (i % 3) * 3;
      REP(a, 3) REP(b, 3) REP(c, 3) REP(d, 3) if(a != c && b != d && v[a + y][b + x] == v[c + y][d + x]) f[a + y][b + x] = f[c + y][d + x] = true;
    }
    REP(i, H){
      REP(j, W) cout <<(f[i][j] ? "*" : " ") <<v[i][j];
      cout <<endl;
    }
  }
  return 0;
}