#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int hyou[10][10];
	int sum;
	int n;

	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int s[10] = {0};

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> hyou[i][j];
			}
		}

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

	return 0;


}