#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int n;
	while(cin>>n,n!=0){
		int a[n+1][n+1];
		for(int i=0;i<n;i++){
			a[n][i]=0;a[i][n]=0;
		}
		a[n][n]=0;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>a[i][j];
				//cout<<a[i][j]<<" ";
				a[i][n]+=a[i][j];
				a[n][j]+=a[i][j];
			}
			//cout<<endl;
		}
		
		for(int i=0;i<n;i++)a[n][n]+=a[n][i];
		
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
			printf("%5d",a[i][j]);
			}
			cout<<endl;
		}
		
	}

}