#include <iostream>
#include <iomanip>
using namespace std;

int main(void){
    int n, a[11][11], i, j ;
    cin >> n;
    
    while(n != 0){
        //初期化
        for(i=0; i<=10; i++){
            for(j=0; j<=10; j++){
                a[i][j]=0;
            }
        }
        
        for(i=0; i<n; i++){
            for(j=0; j<n; j++){
                cin >> a[i][j];
                a[i][n] += a[i][j];
                a[n][j] += a[i][j];
                cout << setw(5) << a[i][j];
            }
            a[n][n] += a[i][n];
            cout << setw(5) << a[i][n] << endl;
        }
        for(j=0; j<=n; j++){
            cout << setw(5) << a[n][j];
        }
        cout << endl;
        cin >> n;
    }
    return 0;
}

