#include <iostream>
#include <math.h>
using namespace std;

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		cin >> N;
		if (N == 0)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				cin >> table[i][j];
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-(log10(table[i][j])+1);k++) {
					cout << " ";
				}
				cout << table[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}