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 {
		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()
		}
		n--
	}
}

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

Python: # Aizu Problem 00126: Puzzle
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def check_puzzle(puzzle):
    marker = [[' ' for _ in range(9)] for __ in range(9)]
    # check rows:
    for r in range(9):
        row = puzzle[r]
        for k in range(1, 10):
            if row.count(k) != 1:
                for idx in [j for j in range(9) if row[j] == k]:
                    marker[r][idx] = '*'
    # check columns:
    for c in range(9):
        col = [puzzle[r][c] for r in range(9)]
        for k in range(1, 10):
            if col.count(k) != 1:
                for idx in [j for j in range(9) if col[j] == k]:
                    marker[idx][c] = '*'
    # check sub-squares:
    for rs in range(3):
        for rc in range(3):
            square = puzzle[3*rs][3*rc:3*rc+3] + puzzle[3*rs+1][3*rc:3*rc+3] + \
                     puzzle[3*rs+2][3*rc:3*rc+3]
            for k in range(1, 10):
                if square.count(k) != 1:
                    for idx in [j for j in range(9) if square[j] == k]:
                        ridx = 3 * rs + idx // 3
                        cidx = 3 * rc + idx % 3
                        marker[ridx][cidx] = '*'
            
    return marker


first = True
N = int(input())
for n in range(N):
    puzzle = [[int(_) for _ in input().split()] for __ in range(9)]
    marker = check_puzzle(puzzle)
    if first:
        first = False
    else:
        print()
    for k in range(9):
        out = ''.join([marker[k][j] + str(puzzle[k][j]) for j in range(9)])
        print(out)

Python: # Aizu Problem 00126: Puzzle
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def check_puzzle(puzzle):
    marker = [[' ' for _ in range(9)] for __ in range(9)]
    # check rows:
    for r in range(9):
        row = puzzle[r]
        for k in range(1, 10):
            if row.count(k) != 1:
                for idx in [j for j in range(9) if row[j] == k]:
                    marker[r][idx] = '*'
    # check columns:
    for c in range(9):
        col = [puzzle[r][c] for r in range(9)]
        for k in range(1, 10):
            if col.count(k) != 1:
                for idx in [j for j in range(9) if col[j] == k]:
                    marker[idx][c] = '*'
    # check sub-squares:
    for rs in range(3):
        for rc in range(3):
            square = puzzle[3*rs][3*rc:3*rc+3] + puzzle[3*rs+1][3*rc:3*rc+3] + \
                     puzzle[3*rs+2][3*rc:3*rc+3]
            for k in range(1, 10):
                if square.count(k) != 1:
                    for idx in [j for j in range(9) if square[j] == k]:
                        ridx = 3 * rs + idx // 3
                        cidx = 3 * rc + idx % 3
                        marker[ridx][cidx] = '*'
            
    return marker


first = True
N = int(input())
for n in range(N):
    puzzle = [[int(_) for _ in input().split()] for __ in range(9)]
    marker = check_puzzle(puzzle)
    if first:
        first = False
    else:
        print()
    for k in range(9):
        out = ''.join([marker[k][j] + str(puzzle[k][j]) for j in range(9)])
        print(out)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0126

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline




def solve(data):
    status = [[' '] * 9 for _ in range(9)]

    # ?¨???????????????§??????
    for y, row in enumerate(data):
        freq = defaultdict(int)
        for i, n in enumerate(row):
            if n in freq:
                freq[n].append(i)
            else:
                freq[n] = [i]
        for k, v in freq.items():
            if len(v) > 1:
                for ind in v:
                    status[y][ind] = '*'

    # ?????????????????§??????
    for x in range(9):
        freq = defaultdict(int)
        for y in range(9):
            n = data[y][x]
            if n in freq:
                freq[n].append(y)
            else:
                freq[n] = [y]
        for k, v in freq.items():
            if len(v) > 1:
                for ind in v:
                    status[ind][x] = '*'

    # 3x3????????§??????
    for y in range(0, 9, 3):
        for x in range(0, 9, 3):
            freq = defaultdict(int)
            for yy in range(3):
                for xx in range(3):
                    n = data[y+yy][x+xx]
                    if n in freq:
                        freq[n].append((x+xx, y+yy))
                    else:
                        freq[n] = [(x+xx, y+yy)]

            for k, v in freq.items():
                if len(v) > 1:
                    for xx, yy in v:
                        status[yy][xx] = '*'

    for y in range(9):
        for x in range(9):
            print('{}{}'.format(status[y][x], data[y][x]), end='')
        print()


def main(args):
    n = int(input())
    for i in range(n):
        data = [[int(x) for x in input().split()] for _ in range(9)]
        result = solve(data)
        if i != n-1:
            print()



if __name__ == '__main__':
    main(sys.argv[1:])

Python: n=int(input())
st=True
for _ in range(n):
    if st==False:
        print()

    puzzle=[]
    for i in range(9):
        row=[int(j) for j in input().split(" ")]
        puzzle.append(row)

    dup=[[False for i in range(9)] for j in range(9)]
    for i in range(9):
        for j in range(9):
            for k in range(9):
                if i!=k and puzzle[i][j]==puzzle[k][j]:
                    dup[i][j]=True
                if j!=k and puzzle[i][j]==puzzle[i][k]:
                    dup[i][j]=True

            for p in range(3):
                for q in range(3):
                    x=(i//3)*3+p
                    y=(j//3)*3+q
                    if (x==i and y==j):
                        continue

                    if puzzle[x][y]==puzzle[i][j]:
                        dup[i][j]=True

    for i in range(9):
        for j in range(9):
            if dup[i][j]:
                print("*", end="")
            else:
                print(" ", end="")
            print(puzzle[i][j], end="")
        print()
    st=False