#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int dy[] = {0, 0, 0, 1, 1, 1, 2, 2, 2};
int dx[] = {0, 1, 2, 0, 1, 2, 0, 1, 2};

void solve() {
  int a[9][9], wa[9][9] = {};
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      cin >> a[i][j];
    }
  }
  for (int d = 1; d < 10; d++) {
    for (int i = 0; i < 9; i++) {
      int cnt = 0;
      for (int j = 0; j < 9; j++) {
        cnt += a[i][j] == d;
      }
      if (cnt == 1) continue;
      for (int j = 0; j < 9; j++) {
        if (a[i][j] == d) wa[i][j] = 1;
      }
    }
    for (int j = 0; j < 9; j++) {
      int cnt = 0;
      for (int i = 0; i < 9; i++) {
        cnt += a[i][j] == d;
      }
      if (cnt == 1) continue;
      for (int i = 0; i < 9; i++) {
        if (a[i][j] == d) wa[i][j] = 1;
      }
    }
    for (int i = 0; i < 9; i += 3) {
      for (int j = 0; j < 9; j += 3) {
        int cnt = 0;
        for (int k = 0; k < 9; k++) {
          int ny = i + dy[k], nx = j + dx[k];
          cnt += a[ny][nx] == d;
        }
        if (cnt == 1) continue;
        for (int k = 0; k < 9; k++) {
          int ny = i + dy[k], nx = j + dx[k];
          if (a[ny][nx] == d) wa[ny][nx] = 1;
        }
      }
    }
  }
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      cout << " *"[wa[i][j]] << a[i][j];
    }
    cout << endl;
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    if (i) cout << endl;
    solve();
  }

  return 0;
}
