def main
  while (n = gets.to_i) != 0
    table = Array.new(n + 1)
    table[n] = Array.new(n + 1, 0)
    n.times do |i|
      table[i] = gets.split(" ").map(&:to_i)
      table[i] << table[i][0..-1].inject{|sum, item|sum + item}
      table[i].each_with_index{|item, idx|table[n][idx] += item}
    end
    puts table.collect{|item|express(item)}
  end      
end
def express(line)
  line.map{|item|sprintf("%#5d", item)}.join("")
end
main