#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<vector<int>> v(n+1, vector<int>(n+1));
        for (int i = 0; i < n; ++i) {
            int s = 0;
            for (int j = 0; j < n; ++j) {
                cin >> v[i][j];
                s += v[i][j];
            }
            v[i].back() = s;
        }
        for (int i = 0; i < n+1; ++i) {
            int s = 0;
            for (int j = 0; j < n; ++j) {
                s += v[j][i];
            }
            v.back()[i] = s;
        }
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= n; ++j) {
                printf("%5d", v[i][j]);
            }
            puts("");
        }
    }
    return 0;
}
