#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int a[15][15] = {};
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        a[i][n] += a[i][j];
      }
    }
    for (int j = 0; j <= n; j++) {
      for (int i = 0; i < n; i++) {
        a[n][j] += a[i][j];
      }
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        cout << setw(5) << a[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}
