#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int a[53][53];

int main()
{
    int n;
    while (cin >> n, n)
    {
        int r_sum[n] = {}, c_sum[n] = {}, sum = 0;
        rep(i, n)
        {
            rep(j, n)
            {
                cin >> a[i][j];
                r_sum[i] += a[i][j];
                c_sum[j] += a[i][j];
                sum += a[i][j];
            }
        }
        r_sum[n] = sum;

        rep(j, n) a[n][j] = c_sum[j];

        rep(i, n + 1)
        {
            rep(j, n)
            {
                cout << right << setw(5) << a[i][j];
            }
            cout << right << setw(5) << r_sum[i] << endl;
        }
    }
    return 0;
}
