while 1:

  n=eval(input())+1

  if n==1: break

  x=[]

  y=[0]*n

  for i in range(n-1):

    a=list(map(int,input().split()))

    a.append(sum(a))

    x.append(a)

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

  x.append(y)

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

  n = eval(input())

  if n==0: break

  x = []

  y = [0]*(n+1)

  for i in range(n):

    a=list(map(int, input().split()))

    a.append(sum(a))

    x.append(a)

    for j in range(n+1): y[j] += a[j]

  x.append(y)

  for a in x: print("".join([str(e).rjust(5) for e in a]))
while 1:
    n = eval(input()) + 1
    if n == 1:
        break
    x = []
    y = [0] * n
    for i in range(n - 1):
        a = list(map(int, input().split()))
        a.append(sum(a))
        x.append(a)
        for i in range(n):
            y[i] += a[i]
    x.append(y)
    for a in x:
        print("".join([str(x).rjust(5) for x in a]))

while 1:
    n = eval(input())
    if n == 0:
        break
    x = []
    y = [0] * (n + 1)
    for i in range(n):
        a = list(map(int, input().split()))
        a.append(sum(a))
        x.append(a)
        for j in range(n + 1):
            y[j] += a[j]
    x.append(y)
    for a in x:
        print("".join([str(e).rjust(5) for e in a]))

-    n = eval(input()) + 1 -    if n == 1: +    n = eval(input()) +    if n == 0: -    y = [0] * n -    for i in range(n - 1): +    y = [0] * (n + 1) +    for i in range(n): -        for i in range(n): -            y[i] += a[i] +        for j in range(n + 1): +            y[j] += a[j] -        print("".join([str(x).rjust(5) for x in a])) +        print("".join([str(e).rjust(5) for e in a]))