def get_all_index(a, value)
  index = []
  while a.include?(value)
    next_i = a.index(value)
    index << next_i
    a[next_i] = nil
  end
  index
end

def checker(line)
  line_checker = []
  line.each do |l|
    if (mistakes = l.uniq.select{|i| l.index(i) != l.rindex(i)}).any?
      temp = []
      mistakes.each do |mistake|
        temp << get_all_index(l, mistake)
      end
      line_checker << temp.flatten
    end
  end
  line_checker
end

n = gets.to_i
virgin = true

n.times do
  puzzle = []
  errata = []
  
  puts "" unless virgin

  9.times do
    puzzle << gets.split.map(&:to_i)
    errata << Array.new(9, false)
  end

  column = puzzle

  row = Array.new(9)
  row.map!{[]}
  0.upto(8) do |i|
    0.upto(8) do |j|
      row[i] << puzzle[j][i]
    end
  end

  row_checker = checker(row)
  column_checker = checker(column)

  row_checker.each_with_index do |rs, i|
    if rs.any?
      rs.each { |r| errata[r][i] = true }
    end
  end

  column_checker.each_with_index do |cs, i|
    if cs.any?
      cs.eac { |c| errata[i][c] = true }
    end
  end

  0.upto(8) do |i|
    0.upto(8) do |j|
      if errata[i][j]
        print "*#{puzzle[i][j]}"
      else
        print " #{puzzle[i][j]}"
      end
      puts "" if j == 8
    end
  end

  virgin = false if virgin
end