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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector< vector<int> > data(n + 1, vector<int>(n + 1));
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> data[i][j];
			}
			int row_sum = 0;
			for(int j = 0; j < n; ++j)
			{
				row_sum += data[i][j];
			}
			data[i][n] = row_sum;
			sum += row_sum;
		}
		data[n][n] = sum;
		for(int i = 0; i < n; ++i)
		{
			int column_sum = 0;
			for(int j = 0; j < n; ++j)
			{
				column_sum += data[j][i];
			}
			data[n][i] = column_sum;
		}
		for(int i = 0; i < n + 1; ++i)
		{
			for(int j = 0; j < n + 1; ++j)
			{
				printf("%5d", data[i][j]);
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}