#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<vector<int>> vec(n + 1, vector<int>(n + 1, 0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> vec[i][j];
        vec[i][n] += vec[i][j];
        vec[n][j] += vec[i][j];
      }
    }
    vec[n][n] = accumulate(vec[n].begin(), vec[n].end(), 0);

    for (auto &seq : vec) {
      for (auto &v : seq)
        cout << setw(5) << v;
      cout << endl;
    }
  }
}
