while True:

    n = int(input())

    if n == 0:

        break



    a = [[] for i in range(n + 1)]

    for i in range(n + 1):

        if i < n:

            a[i] = list(map(int, input().split()))

            a[i].append(sum(a[i]))

        else:

            a[i] = [sum([a[j][k] for j in range(n)]) for k in range(n + 1)]



    s = ""

    for i in range(n + 1):

        s += "".join([str(x).rjust(5, " ") for x in a[i]]) + "\n"

    print(s, end=' ')
while True:

    n = int(input())

    if n == 0:

        break



    a = [[] for i in range(n + 1)]

    for i in range(n + 1):

        if i < n:

            a[i] = list(map(int, input().split()))

            a[i].append(sum(a[i]))

        else:

            a[i] = [sum([a[j][k] for j in range(n)]) for k in range(n + 1)]



    for i in range(n + 1):

        print("".join([str(x).rjust(5, " ") for x in a[i]]) + "\n", end=' ')
while True:
    n = int(input())
    if n == 0:
        break
    a = [[] for i in range(n + 1)]
    for i in range(n + 1):
        if i < n:
            a[i] = list(map(int, input().split()))
            a[i].append(sum(a[i]))
        else:
            a[i] = [sum([a[j][k] for j in range(n)]) for k in range(n + 1)]
    s = ""
    for i in range(n + 1):
        s += "".join([str(x).rjust(5, " ") for x in a[i]]) + "\n"
    print(s, end=" ")

while True:
    n = int(input())
    if n == 0:
        break
    a = [[] for i in range(n + 1)]
    for i in range(n + 1):
        if i < n:
            a[i] = list(map(int, input().split()))
            a[i].append(sum(a[i]))
        else:
            a[i] = [sum([a[j][k] for j in range(n)]) for k in range(n + 1)]
    for i in range(n + 1):
        print("".join([str(x).rjust(5, " ") for x in a[i]]) + "\n", end=" ")

-    s = "" -        s += "".join([str(x).rjust(5, " ") for x in a[i]]) + "\n" -    print(s, end=" ") +        print("".join([str(x).rjust(5, " ") for x in a[i]]) + "\n", end=" ")