Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	for 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
}

Python: from __future__ import print_function
from sys import stdin, stdout

try:
    xrange
except NameError:
    pass
else:
    range = xrange

def solve():
    table = []
    for _ in range(9):
        table.append(stdin.readline().split())
    
    check_table = []
    for _ in range(9):
        check_table.append([False] * 9)
    
    # horizontal check
    for i in range(9):
        a = []
        for j in range(9):
            a.append(table[i][j])
        for j in range(9):
            n = table[i][j]
            if a.count(n) > 1:
                check_table[i][j] = True
    
    # vertical check
    for j in range(9):
        a = []
        for i in range(9):
            a.append(table[i][j])
        for i in range(9):
            n = table[i][j]
            if a.count(n) > 1:
                check_table[i][j] = True
    
    # 9x9 check
    for i in range(0, 9, 3):
        for j in range(0, 9, 3):
            a = []
            for di in range(3):
                for dj in range(3):
                    a.append(table[i + di][j + dj])
            for di in range(3):
                for dj in range(3):
                    n = table[i + di][j + dj]
                    if a.count(n) > 1:
                        check_table[i + di][j + dj] = True
    
    for i in range(9):
        for j in range(9):
            if check_table[i][j]:
                stdout.write('*')
            else:
                stdout.write(' ')
            stdout.write(table[i][j])
        stdout.write('\n')
    stdout.write('\n')

if __name__ == '__main__':
    N = int(stdin.readline())
    for _ in range(N):
        solve()

Python: n = int(input())

"""
def hor(matrix,y):
    res = [True]*9
    s = set()
    out = set()
    for i in matrix[y]:
        if i in s:
            out.add(i)
        s.add(i)
    for ind,i in enumerate(matrix[y]):
        if i in out:
            res[ind] = False
"""
def so(seq):
    res = [False]*9
    s = set()
    out = set()
    for i in seq:
        if i in s:
            out.add(i)
        s.add(i)
    for ind,i in enumerate(seq):
        if i in out:
            res[ind] = True
    return res

for num in range(n):
    matrix = [list(map(int, input().split())) for _ in range(9)]
    part = []
    for i in range(9):
        t = []
        for j in range(9):
            t.append(matrix[j][i])
        part.append(t)
    section = []
    for i in range(3):
        for j in range(3):
            t = []
            for k in range(3):
                for l in range(3):
                    t.append(matrix[i*3 + k][j*3 + l])
            section.append(t)   
        
    cor = [[False]*9 for _ in range(9)]

    for i in range(9):
        for ind,j in enumerate(so(matrix[i])):
            cor[i][ind] = cor[i][ind] or j
        for ind,j in enumerate(so(part[i])):
            cor[ind][i] = cor[ind][i] or j
        for ind,j in enumerate(so(section[i])):
            x = i % 3
            y = i // 3
            px = ind % 3
            py = ind // 3
            cor[y*3 + py][x*3 + px] = cor[y*3 + py][x*3 + px] or j
    for i,j in zip(cor, matrix):
        for k,l in zip(i,j):
            if k: t = '*'
            else: t = ' '
            print(f'{t}{l}',end='')
        print()
    if num != n-1: print()

Python: from collections import Counter

CounterKey = ("1", "2", "3", "4", "5", "6", "7", "8", "9")

inputCount = int(input())

for _ in range(inputCount):
    puzzle = []
    mark = []

    if _ != 0:
        print()

    for lp in range(9):
        puzzle.append([item for item in input().split(" ")])
        mark.append([item for item in " " * 9])

    # 横
    for rowIndex, row in enumerate(puzzle):
        counter = Counter(row)
        needNum = [num for num in CounterKey if 1 < counter[num]]

        if not needNum:
            continue

        for colIndex, item in enumerate(row):
            if item in needNum:
                mark[rowIndex][colIndex] = "*"

    # 縦
    for colIndex, col in enumerate(
            zip(puzzle[0], puzzle[1], puzzle[2], puzzle[3], puzzle[4], puzzle[5], puzzle[6], puzzle[7], puzzle[8])):
        counter = Counter(col)
        needNum = [num for num in CounterKey if 1 < counter[num]]

        if not needNum:
            continue

        for rowIndex, item in enumerate(col):
            if item in needNum:
                mark[rowIndex][colIndex] = "*"

    # 四角
    for lp in range(3):
        block = []

        for blockCount, col in enumerate(zip(puzzle[lp * 3], puzzle[lp * 3 + 1], puzzle[lp * 3 + 2])):
            block.extend(col)

            if blockCount % 3 - 2 == 0:

                counter = Counter(block)
                needNum = [num for num in CounterKey if 1 < counter[num]]

                if needNum:

                    for index, item in enumerate(block):
                        if item in needNum:
                            rowIndex, colIndex = lp * 3 + index % 3, blockCount - 2 + index // 3
                            mark[rowIndex][colIndex] = "*"

                block = []

    # 出力
    for p, m in zip(puzzle, mark):
        output = []

        for num, state in zip(p, m):
            output.append(state)
            output.append(num)

        print("".join(output))