loop {
	n=gets.chomp.to_i
	break if n==0
	matrix=Array.new(n+1,Array.new(n+1,0))


	for i in 0..n-1
		matrix[i] = gets.chomp.split(" ").map{|i| i.to_i}
		matrix[i][n] = matrix[i].inject(:+)
		for j in 0..n	
			matrix[n][j] += matrix[i][j]
		end
	end

	for i in 0..n
		puts matrix[i].map{|j| j.to_s.rjust(5)}.join
	end

}