L = 9
T = L / 3

def check(line)
  co = Hash.new(0)
  line.each_with_index {|num, i| co[num] += 1}
  (0...L).select {|i| co[line[i]] > 1}
end

def square
  L.times {|i| yield(i % T, i / T)}
end

result = []

$<.gets.to_i.times do
  field = Array.new(L) {$<.gets.split.map(&:to_i)}
  marked = []
  
  field.each_with_index do |row, i|
    marked += check(row).map {|j| i * L + j}
  end
  L.times do |i|
    col = Array.new(L) {|j| field[j][i]}
    marked += check(col).map {|k| k * L + i}
  end
  square do |x, y|
    sx, sy = x * T, y * T
    block = Array.new(L) {|i| field[sy + i / T][sx + i % T]}
    marked += check(block).map {|i| (sy + i / T) * L + sx + i % T}
  end
  
  result << field.flatten.map.with_index do |num, i|
    str = (marked.include?(i) ? "*" : " ") + num.to_s
    str + ((i % L == L - 1) ? "\n" : "")
  end.join
end

puts result.join("\n")
