while (num = gets.chomp.to_i) != 0
  ary = []
  num.times do
    tmp = gets.split.map(&:to_i)
    ary << tmp.push(tmp.inject(:+))
  end
  tmp = ary[0].zip(ary[1], ary[2], ary[3]).map {|item| item.inject(:+)}
  ary << tmp
  ary.each {|item| item.map! {|item2| item2.to_s.rjust(5)}}
  ary.each {|item| puts item.join}
end