Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	table := [9][9]int{}
	check := [9][9]bool{}
	n, _ := strconv.Atoi(scanner.Text())
	for n > 0 {
		n--
		for i := 0; i < 9; i++ {
			for j := 0; j < 9; j++ {
				table[i][j] = nextInt()
			}
		}
		for i := 0; i < 9; i++ {
			for j := 0; j < 9; j++ {
				ok := true
				for k := 0; k < 9; k++ {
					if table[i][j] == table[i][k] && j != k {
						ok = false
					}
				}
				for k := 0; k < 9; k++ {
					if table[i][j] == table[k][j] && i != k {
						ok = false
					}
				}
				seci := i / 3
				secj := j / 3
				for k := 0; k < 3; k++ {
					for l := 0; l > 3; l++ {
						if table[seci*3+k][secj*3+l] == table[i][j] && seci*3+k != i && secj*3+l != j {
							ok = false
						}
					}
				}
				if !ok {
					check[i][j] = true
				}
			}
		}
		for i := 0; i < 9; i++ {
			for j := 0; j < 9; j++ {
				if check[i][j] {
					fmt.Print("*")
				} else {
					fmt.Print(" ")
				}
				fmt.Print(table[i][j])
			}
			fmt.Println()
		}
		if n != 0 {
			fmt.Println()
		}
	}
}

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

bool cmp(const pair<int,string>& a, const pair<int,string>& b){
    return a.first < b.first;
}
int main() {
    //cout << fixed << setprecision(15);

    int n; cin >> n;
    int cnt=0;
    REP(T, n){
        if(cnt) cout << endl;
        cnt++;
        vector<vector<int>> v(10);

        REP(i, 9) REP(j, 9){
            int c; cin >> c;
            v[i].push_back(c);
        }

        bool check[9][9];
        REP(i, 9) REP(j, 9) check[i][j] = true;

        REP(i, 9) {
            int cnt[15]={0};
            //横方向の加算
            REP(j, 9) {
                cnt[v[i][j]]++;
            }

            REP(j, 9){
                if(cnt[v[i][j]]>1){
                    check[i][j] = false;
                }
            }
        }

        REP(i, 9) {
            int cnt[10]={0};
            //横方向の加算
            REP(j, 9) {
                cnt[v[j][i]]++;
            }

            REP(j, 9){
                if(cnt[v[j][i]]>1){
                    check[j][i] = false;
                }
            }
        }
        
        int cnt[10]={0};
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+1][j+1]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+1][x+1] == i){
                            check[y+1][x+1] = false;
                        }
                    }
                }
            }
        }
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+1][j+5]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+1][x+5] == i){
                            check[y+1][x+5] = false;
                        }
                    }
                }
            }
        }
        
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+1][j+8]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+1][x+8] == i){
                            check[y+1][x+8] = false;
                        }
                    }
                }
            }
        }
        
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+5][j+8]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+5][x+8] == i){
                            check[y+5][x+8] = false;
                        }
                    }
                }
            }
        }
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+8][j+8]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+8][x+8] == i){
                            check[y+8][x+8] = false;
                        }
                    }
                }
            }
        }
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+5][j+1]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+5][x+1] == i){
                            check[y+5][x+1] = false;
                        }
                    }
                }
            }
        }
        
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+5][j+5]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+5][x+5] == i){
                            check[y+5][x+5] = false;
                        }
                    }
                }
            }
        }
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+8][j+1]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+8][x+1] == i){
                            check[y+8][x+1] = false;
                        }
                    }
                }
            }
        }
        
        REP(i, 10) cnt[i]=0;
        for(int i=-1; i<=1; ++i){
            for(int j=-1; j<=1; ++j){
                cnt[v[i+8][j+5]];
            }
        }
        for(int i=1; i<10; ++i){
            if(cnt[i]>1){
                for(int y=-1; y<=1; ++y){
                    for(int x = -1; x <= 1; ++x){
                        if(v[y+8][x+5] == i){
                            check[y+8][x+5] = false;
                        }
                    }
                }
            }
        }
        
        for(int i=0; i<9; ++i){
            for(int j=0; j<9; ++j){
                if(!check[i][j]){
                    cout <<"*" << v[i][j];
                }else{
                    cout << " " << v[i][j];
                }
                    
               
            }
            cout << endl;
        }
    }
    return 0;
}