#include <cstdio>

using namespace std;

int main(void){
	int t[11][11], n, i, j, sum;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				scanf("%d",&t[i][j]);
			}
		}
		for(i = 0;i < n;i++){
			sum = 0;
			for(j = 0;j < n;j++){
				sum += t[i][j];
			}
			t[i][j] = sum;
			sum = 0;
			for(j = 0;j < n;j++){
				sum += t[j][i];
			}
			t[j][i] = sum;
		}
		sum = 0;
		for(j = 0;j < n;j++){
			sum += t[i][j];
		}
		t[i][i] = sum;
		for(i = 0;i < n + 1;i++){
			for(j = 0;j < n + 1;j++){
				printf("%5d",t[i][j]);
				if(j != n) printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}