#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n != 0){
		vector<vector<int> > ans(n+1, vector<int>(n+1, 0));
	
		for(int i = 0; i < n; i++){
			int total = 0;
			for(int j = 0; j < n; j++){
				cin >> ans[i][j];
				total += ans[i][j];
				ans[n][j] += ans[i][j];
			}
			ans[i][n] = total;
			ans[n][n] += total;
		}

		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", ans[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}