#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include<iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int dat[16][16];
	int n;
	while(cin>>n,n){
		rep(i,n){
			rep(j,n){
				dat[j][i]=0;
			}
		}
		int ssum=0;
		rep(i,n){
			int sum=0;
			rep(j,n){
				cin>>dat[j][i];
				sum+=dat[j][i];
			}
			ssum+=sum;
			dat[n][i]=sum;
		}
		dat[n][n]=ssum;
		rep(i,n){
			int sum=0;
			rep(j,n){
				sum+=dat[i][j];
			}
			dat[i][n]=sum;
		}
		rep(i,n+1){
			rep(j,n){
				cout<<setw(5)<<dat[j][i];
			}
			cout<<setw(5)<<dat[n][i]<<endl;
		}
	}
	return 0;
}