#include <iostream>
using namespace std;

int Matrix[11][11];

int main(void){
  int n;
  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> Matrix[i][j];
    int s = 0;
    for(int i = 0; i < n; i++){
      int sumt = 0, sumy = 0;
      for(int j = 0; j < n; j++){
        sumt += Matrix[i][j];
        sumy += Matrix[j][i];
      }
      Matrix[i][n] = sumt;
      Matrix[n][i] = sumy;
      s += sumt + sumy;
    }
    Matrix[n][n] = s;
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", Matrix[j][i]);
      }
      cout << endl;
    }
  }
  return 0;
}