#include <bits/stdc++.h>
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  while(N--){
    int f[9][9];
    for(int i = 0; i < 9; i++){
      for(int j = 0; j < 9; j++){
        cin >> f[i][j];
        f[i][j]--;
      }
    }
    vector< vector<bool> > wrong(9, vector<bool>(9, false));
    vector<bool> used(9, false);
    //columm
    for(int i = 0; i < 9; i++){
      used = vector<bool>(9, false);
      list<int> t;
      for(int j = 0; j < 9; j++){
        if(used[ f[i][j] ] == true){
          t.push_back(f[i][j]);
        }else{
          used[ f[i][j] ] = true;
        }
      }
      for(int j = 0; j < 9; j++){
        for(list<int>::iterator it = t.begin(); it != t.end(); it++){
          if(f[i][j] == *it){
            wrong[i][j] = true;
          }
        }
      }
    }

    //row
    for(int j = 0; j < 9; j++){
      used = vector<bool>(9, false);
      list<int> t;
      for(int i = 0; i < 9; i++){
        if(used[ f[i][j] ] == true){
          t.push_back(f[i][j]);
        }else{
          used[ f[i][j] ] = true;
        }
      }
      for(int i = 0; i < 9; i++){
        for(list<int>::iterator it = t.begin(); it != t.end(); it++){
          if(f[i][j] == *it){
            wrong[i][j] = true;
          }
        }
      }
    }

    //sp area
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){

        used = vector<bool>(9, false);
        list<int> t;
        for(int k = 0; k < 3; k++){
          for(int l = 0; l < 3; l++){
            if(used[ f[i*3+k][j*3+l] ] == true){
              t.push_back(f[i*3+k][j*3+l]);
            }else{
              used[ f[i*3+k][j*3+l] ] = true;
            }
          }
        }
        for(int k = 0; k < 3; k++){
          for(int l = 0; l < 3; l++){
            for(list<int>::iterator it = t.begin(); it != t.end(); it++){
              if(f[i*3+k][j*3+l] == *it){
                wrong[i*3+k][j*3+l] = true;
              }
            }
          }
        }
      }
    }

    for(int i = 0; i < 9; i++){
      for(int j = 0; j < 9; j++){
        if(wrong[i][j]) cout << "*";
        else cout << " ";
        cout << f[i][j]+1;
      }
      cout << endl;
    }
  }

  return 0;
}