#include <bits/stdc++.h>

using namespace std;


int main(void) {
    int n;
    while (scanf("%d", &n), n) {
        int a[110][110] = {};
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                scanf("%d", &a[i][j]);
        
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                a[i][n] += a[i][j];
        
        for (int j = 0; j <= n; j++)
            for (int i = 0; i < n; i++)
                a[n][j] += a[i][j];
        
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++)
                printf("%5d", a[i][j]);
            puts("");
        }
    }

    return 0;
}
