#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    while(cin >> n){
        if(!n) break;

        int table[n+1][n+1];
        rep(i,n+1) table[i][n] = 0, table[n][i] = 0;

        rep(i,n)rep(j,n){
            cin >> table[i][j];
            table[i][n] += table[i][j];
            table[n][j] += table[i][j];
        }
        rep(i,n) table[n][n] += table[i][n];

        rep(i,n+1){
            rep(j,n){
                printf("%5d",table[i][j]);
            }
            printf("%5d\n",table[i][n]);
        }
    }

    return 0;
}
