#include <cstdio>
int imap[10000][10000];

int main() {

    int n, t, sum;
    for(; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            sum = 0;
            for (int j = 0; j < n; j++) {
                scanf("%d", &t);
                sum+=t;
                imap[i][j] = t;
            }
            imap[i][n] = sum;
        }
        for (int i = 0; i <= n; i++) {
            sum = 0;
            for (int j = 0; j < n; j++) {
                sum+= imap[j][i];
            }
            imap[n][i] = sum;
        }

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <=n; j++) {
                printf("%5d", imap[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}

