#include<iostream>
#include<cstdio>
using namespace std;

int main(){

  int n;
  int a[1000][1000],b;

  while(cin >> n, n){

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++) cin >> a[i][j];
    }

    for(int i=0;i<n;i++){
      b = 0;

      for(int j=0;j<n;j++) b += a[i][j];

      a[i][n] = b;

    }

    for(int j=0;j<n;j++){
      b = 0;

      for(int i=0;i<n;i++) b += a[i][j];

      a[n][j] = b;

    }

    b = 0;
    for(int i=0;i<n;i++) b += a[i][n];
    a[n][n] = b;

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++) printf("%5d",a[i][j]);
      cout << endl;
    }

  }
}