def show r
  puts sprintf('%5d' * 5, *r)
end
until (n = gets.to_i) == 0
  show n.times
    .lazy
    .map { gets.split(' ').map(&:to_i) }
    .map {|r| (r << r.reduce(:+)).tap(&method(:show)) }
    .reduce {|m, r| m.zip(r).map {|p| p.reduce(:+) } }
end