while True:

	n = eval(input())

	if n == 0: break

	ls = [list(map(int, input().split()))+[0] for i in range(n)]+[[0]*(n+1)]

	for row in range(n+1):

		for col in range(n):

			ls[n][col] += ls[row][col] if row != n else 0

			ls[row][n] += ls[row][col]

		print("".join([str(x).rjust(5) for x in ls[row]]))
while 1:

	n = eval(input())

	if n == 0: break

	l = [list(map(int, input().split()))+[0] for i in range(n)]+[[0]*(n+1)]

	for r in range(n+1):

		for c in range(n):

			l[n][c] += l[r][c] if r != n else 0

			l[r][n] += l[r][c]

		print("".join([str(x).rjust(5) for x in l[r]]))
while True:
    n = eval(input())
    if n == 0:
        break
    ls = [list(map(int, input().split())) + [0] for i in range(n)] + [[0] * (n + 1)]
    for row in range(n + 1):
        for col in range(n):
            ls[n][col] += ls[row][col] if row != n else 0
            ls[row][n] += ls[row][col]
        print("".join([str(x).rjust(5) for x in ls[row]]))

while 1:
    n = eval(input())
    if n == 0:
        break
    l = [list(map(int, input().split())) + [0] for i in range(n)] + [[0] * (n + 1)]
    for r in range(n + 1):
        for c in range(n):
            l[n][c] += l[r][c] if r != n else 0
            l[r][n] += l[r][c]
        print("".join([str(x).rjust(5) for x in l[r]]))

-while True: +while 1: -    ls = [list(map(int, input().split())) + [0] for i in range(n)] + [[0] * (n + 1)] -    for row in range(n + 1): -        for col in range(n): -            ls[n][col] += ls[row][col] if row != n else 0 -            ls[row][n] += ls[row][col] -        print("".join([str(x).rjust(5) for x in ls[row]])) +    l = [list(map(int, input().split())) + [0] for i in range(n)] + [[0] * (n + 1)] +    for r in range(n + 1): +        for c in range(n): +            l[n][c] += l[r][c] if r != n else 0 +            l[r][n] += l[r][c] +        print("".join([str(x).rjust(5) for x in l[r]]))