#include <iostream>
#include <iomanip>

int main()
{
    int n;
    while (std::cin >> n) {
    
        if (n == 0) break;

        int** p;
        p = new int* [n + 1];
        for (int i = 0; i < n + 1; ++i) {
            p[i] = new int [n + 1];
        }
        
        for (int i = 0; i < n + 1; ++i) {
            for (int j = 0; j < n + 1; ++j) {
                p[i][j] = 0;
            }
        }

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

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

        for (int i = 0; i < n; ++i) {
            p[n][n] += p[i][n];
        }

        for (int i = 0; i < n + 1; ++i) {
            for (int j = 0; j < n + 1; ++j) {
                printf("%5d", p[i][j]);
                if (j == n) std::cout << std::endl;
                
            }
        }

        for (int i = 0; i < n + 1; ++i) {
        delete[] p[i];
        }
    
        delete[] p;
    }
    
    return 0;
}