#include<cstdio>
#include<iostream>
#include<string>
  
using namespace std;
  
int main(void){
  
   int hyo[11][11];
   int n;
   int sum;

   while(1){
	   for(int i=0;i<10;i++){
		   for(int j=0;j<10;j++){
			   hyo[i][j]=0;
		   }
	   }
	   cin>>n;
	   if(n==0) break;
	   for(int i=0;i<n;i++){
		   for(int j=0;j<n;j++){
			   cin>>hyo[i][j];
		   }
	   }
	   for(int i=0;i<n;i++){
		   sum=0;
		   for(int j=0;j<n;j++){
			   sum+=hyo[i][j];
		   }
		   hyo[i][n]=sum;
	   }
	   for(int j=0;j<=n;j++){
		   sum=0;
		   for(int i=0;i<n;i++){
			   sum+=hyo[i][j];
		   }
		   hyo[n][j]=sum;
	   }
	   for(int i=0;i<=n;i++){
		   for(int j=0;j<=n;j++){
			   printf("%5d",hyo[i][j]);
		   }
		   printf("\n");
	   }
   }

  
   return 0;
}