#include<stdio.h>
int main()
{
	int a[11][11],n,i,j;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)
		{
			a[i][n] = 0;
			for(j=0;j<n;++j)
			{
				scanf("%d", &a[i][j]);
				a[i][n] += a[i][j];
			}
		}
		for(j = 0; j <= n; ++j)
		{
			a[n][j] = 0;
			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]);
			}
			putchar('\n');
		}
	}
	return 0;
}
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <memory>
#include <iomanip>

int main(int argc, char* argv[])
{
    while (true) {
        std::string line;
        std::stringstream buffer;
        getline(std::cin, line);
        buffer << line;
        size_t length = 0;
        buffer >> length;
        if (length == 0) break;
        int *total = new int[length + 1];
        size_t width = length + 1;
        memset(total, 0, sizeof(int) * width);
        for (size_t i = 0; i < length; ++i) {
            getline(std::cin, line);
            std::istringstream s(line);
            std::string element;
            int sum = 0;
            for (size_t n = 0; n < length; ++n) {
               getline(s, element, ' ');
               std::stringstream tmp;
                int val = 0;
                tmp << element;
                tmp >> val;
                sum += val;
                total[n] += val;
                std::cout << std::setw(5) << val;
            }
            std::cout << std::setw(5) << sum << std::endl;
            total[length] += sum;
        }
        for (size_t i = 0; i < width; ++i) {
            std::cout << std::setw(5) << total[i];
        }
        std::cout << std::endl;
        delete[] total;
    }
    return 0;
}