#include <iostream>
#include <cstdio>

int main()
{
  int map[10][10];
  int n;

  while (std::cin >> n) {
    if (n == 0) break;

    for (int y = 0; y < n; ++y) {
      map[y][n] = 0;
      for (int x = 0; x < n; ++x) {
        std::cin >> map[y][x];
        map[y][n] += map[y][x];
      }
    }

    for (int x = 0; x <= n; ++x) {
      map[n][x] = 0;
      for (int y = 0; y < n; ++y) {
        map[n][x] += map[y][x];
      }
    }
    
    for (int y = 0; y <= n; ++y) {
      for (int x = 0; x <= n; ++x) {
        printf("%5d", map[y][x]);
      }
      printf("\n");
    }
  }

  return 0;
}