formed_datasets = []

def repeated_num(line)
  line.map { |num, _| num }.sort.each_with_object([]) { |n, a| 
    !a.last.nil? && a.last[0] == n ? a.last[1] += 1 : a << [n, 1]
  }.map { |n, i| n if i > 1 }.compact
end

def checker(arr)
  arr.find_all { |n, _| repeated_num(arr).include?(n) }.map { |_, c| c }
end

def row_check(puzzle)
  puzzle.map { |row| checker(row) }.flatten(1)
end

def column_check(puzzle)
  puzzle.transpose.map { |col| checker(col) }.flatten(1)
end

def square_check(puzzle)
  squared = Array.new(9).map { [] }

  puzzle.each_with_index do |r, i|
    r.each_with_index do |n, j|
      squared[i / 3 * 3 + j / 3] << n
    end
  end
  
  squared.map { |chunk| checker(chunk) }.flatten(1)
end

gets.to_i.times do
  puzzle = Array.new(9) { Array.new(9) }

  9.times do |i|
    gets.split.map(&:to_i).each_with_index { |num, j| puzzle[i][j] = [num, [i, j]]}
  end

  repeated_num_coor =
    (row_check(puzzle) + column_check(puzzle) + square_check(puzzle)).uniq

  formed_datasets << puzzle.map { |row|
    row.map { |n, c| repeated_num_coor.include?(c) ? "*#{n}" : " #{n}" }.join
  }.join("\n")
end

puts formed_datasets.join("\n\n")