#include <iostream>
#include <algorithm>
using namespace std;

class Point {
public:
  int x, y;
  bool exist;
  Point(int x = -1, int y = -1, bool exist = false) : x(x), y(y), exist(exist) {}
};

int main() {
  int n;
  cin >> n;
  bool first = true;
  for(int i = 0; i < n; i++) {
    int data[9][9];
    for(int y = 0; y < 9; y++) {
      for(int x = 0; x < 9; x++) {
	cin >> data[y][x];
      }
    }

    char judge[9][9];
    fill(&judge[0][0], &judge[8][8]+1, ' ');

    Point number[10];
    for(int y = 0; y < 9; y++) {
      fill(&number[0], &number[9]+1, Point(-1,-1,false));
      for(int x = 0; x < 9; x++) {
	if(!number[data[y][x]].exist) {
	  number[data[y][x]].exist = true;
	  number[data[y][x]].x = x;
	  number[data[y][x]].y = y;
	} else {
	  judge[y][x] = '*';
	  judge[number[data[y][x]].y][number[data[y][x]].x] = '*';
	}
      }
    }

    for(int x = 0; x < 9; x++) {
      fill(&number[0], &number[9]+1, Point(-1,-1,false));
      for(int y = 0; y < 9; y++) {
	if(!number[data[y][x]].exist) {
	  number[data[y][x]].exist = true;
	  number[data[y][x]].x = x;
	  number[data[y][x]].y = y;
	} else {
	  judge[y][x] = '*';
	  judge[number[data[y][x]].y][number[data[y][x]].x] = '*';
	}
      }
    }

    for(int j = 0; j < 9; j++) {
      fill(&number[0], &number[9]+1, Point(-1,-1,false));
      for(int k = 0; k < 3; k++) {
	for(int l = 0; l < 3; l++) {
	  int x = (j%3)*3+l;
	  int y = (j/3)*3+k;
	  if(!number[data[y][x]].exist) {
	    number[data[y][x]].exist = true;
	    number[data[y][x]].x = x;
	    number[data[y][x]].y = y;
	  } else {
	    judge[y][x] = '*';
	    judge[number[data[y][x]].y][number[data[y][x]].x] = '*';
	  }
	}
      }
    }


    if(!first) {
      cout << endl;
    } else {
      first = false;
    }
    for(int y = 0; y < 9; y++) {
      for(int x = 0; x < 9; x++) {
	cout << judge[y][x] << data[y][x];
      }
      cout << endl;
    }
  }
  return 0;
}