while True:

    n = int(input())

    if n == 0:

        break

    rows = [list(map(int, input().split())) for _ in range(n)]

    for row in rows:

        print("".join(map("{0:>5}".format, row)), end="")

        print("{:>5}".format(sum(row)))

    columns = list(zip(*rows))

    print("".join(map("{0:>5}".format, list(sum(column) for column in columns))), end="")

    print("{0:>5}".format(sum(sum(row) for row in rows)))

while True:

    n = int(eval(input()))

    if n == 0:

        break

    matrix = [list(map(int, input().split())) for _ in range(n)]

    for i in range(n):

        sum_ = sum(matrix[i])

        print((str("{:>5d}" * (n+1)).format(*matrix[i], sum_)))

    sum_ = [sum(e) for e in list(zip(*matrix))]

    print((str("{:>5d}" * (n+1)).format(*sum_, sum(sum_))))



while True:
    n = int(input())
    if n == 0:
        break
    rows = [list(map(int, input().split())) for _ in range(n)]
    for row in rows:
        print("".join(map("{0:>5}".format, row)), end="")
        print("{:>5}".format(sum(row)))
    columns = list(zip(*rows))
    print(
        "".join(map("{0:>5}".format, list(sum(column) for column in columns))), end=""
    )
    print("{0:>5}".format(sum(sum(row) for row in rows)))

while True:
    n = int(eval(input()))
    if n == 0:
        break
    matrix = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        sum_ = sum(matrix[i])
        print((str("{:>5d}" * (n + 1)).format(*matrix[i], sum_)))
    sum_ = [sum(e) for e in list(zip(*matrix))]
    print((str("{:>5d}" * (n + 1)).format(*sum_, sum(sum_))))

-    n = int(input()) +    n = int(eval(input())) -    rows = [list(map(int, input().split())) for _ in range(n)] -    for row in rows: -        print("".join(map("{0:>5}".format, row)), end="") -        print("{:>5}".format(sum(row))) -    columns = list(zip(*rows)) -    print( -        "".join(map("{0:>5}".format, list(sum(column) for column in columns))), end="" -    ) -    print("{0:>5}".format(sum(sum(row) for row in rows))) +    matrix = [list(map(int, input().split())) for _ in range(n)] +    for i in range(n): +        sum_ = sum(matrix[i]) +        print((str("{:>5d}" * (n + 1)).format(*matrix[i], sum_))) +    sum_ = [sum(e) for e in list(zip(*matrix))] +    print((str("{:>5d}" * (n + 1)).format(*sum_, sum(sum_))))