#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int data[150][150] = { 0 };

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

		}
		for (int i = 0;i < n+1;i++) {
			for (int j = 0;j < n + 1;j++) {
				if (data[i][j] < 10) {
					cout << "    " << data[i][j];
				}
				else if (data[i][j] < 100) {
					cout << "   " << data[i][j];
				}
				else if (data[i][j] < 1000) {
					cout << "  " << data[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;

}