#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <set>
using namespace std;

#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()

int main() {
  int n;
  cin >> n;
  REP(datan,n) {
    if (datan) cout << endl;
    int ba[9][9];
    REP(y,9)
      REP(x,9)
      cin >> ba[x][y];
    multiset<int> block[3][3];
    multiset<int> yoko[9];
    multiset<int> tate[9];
    REP(i,3)
      REP(j,3)
        for (int x = i*3; x<(i+1)*3; x++)
          for (int y = j*3; y<(j+1)*3; y++)
            block[i][j].insert(ba[x][y]);
    REP(i,9) {
      REP(x,9)
        yoko[i].insert(ba[x][i]);
      REP(y,9)
        tate[i].insert(ba[i][y]);
    }
    REP(y,9) {
      REP(x,9) {
        int a = ba[x][y];
        if (block[x/3][y/3].count(a) > 1 || yoko[y].count(a) > 1 || tate[x].count(a) > 1)
          cout << "*";
        else
          cout << " ";
        cout << a;
      }
      cout << endl;
    }
  }
}