#include <stdio.h>

int main(void)
{
	int a[11][11] = {0};
	int n, i, j;

	while (1)
	{
		scanf("%d", &n);

		if (n != 0)
		{
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					scanf("%d", &a[i][j]);

			for (i = 0; i < n; i++)
			{
				for (j = 0; j < n; j++)
					a[i][n] += a[i][j];
				a[n][n] += a[i][n];
			}

			for (j = 0; j < n; j++)
				for (i = 0; i < n; i++)
					a[n][j] += a[i][j];

			for (i = 0; i <= n; i++)
				for (j = 0; j <= n; j++)
				{
					printf("%5d", a[i][j]);
					if (j == n)
						printf("\n");
					else
						printf(" ");
				}
		}
		else
			break;
	}

	return 0;
}