loop{
  n=gets.to_i
  break if n==0
  buf=Array.new
  n.times do 
      buf.push(gets.chop.split(" ").map{|e|e.to_i})
  end
  2.times do
    buf=buf.transpose
    buf.each do |c|
      c.push(c.inject(:+))
    end
  end
  buf.each do |a|
    a.each do |b|
      print '%5d' % [b] 
    end
    puts
  end
}