#include <iostream>
#include <iomanip>

#define MAX_N 10

int a[MAX_N+1][MAX_N+1];
int n;

void solve() {
    // row sum
    for (int i=0; i<n; i++) {
        a[i][n] = 0;
        for (int j=0; j<n; j++) {
            a[i][n] += a[i][j];
        }
    }
    // column sum
    for (int j=0; j<n; j++) {
        a[n][j] = 0;
        for (int i=0; i<n; i++) {
            a[n][j] += a[i][j];
        }
    }
    // total sum
    a[n][n] = 0;
    for (int i=0; i<n; i++) a[n][n] += a[i][n];

    // output
    for (int i=0; i<n+1; i++) {
        for (int j=0; j<n+1; j++) {
            std::cout << std::setw(5) << a[i][j];
        }
        std::cout << std::endl;
    }
}

int main() {
    while(std::cin >> n, n) {
        for (int i=0; i<n; i++) {
            for (int j=0; j<n; j++) {
                std::cin >> a[i][j];
            }
        }
        solve();
    }
}

