#include<iostream>
using namespace std;

int main(){
    int n;
    while(1){
      int sum = 0, s = 0;
      cin >> n;
      if( n == 0) break;
      int poi[n][n];
      for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
         cin >> poi[i][j];
         sum += poi[i][j];
      }
    }
    for(int i = 0;i < n;++i){
    	for(int j = 0;j < n;++j){
    		cout << poi[i][j] << "  ";
    		s += poi[i][j];
    		if(j == n -1){
    			cout << " " << s << endl;
    			s = 0;
    		}
    	}
    }
    for(int i = 0;i < n;++i){
    	for(int j = 0;j < n;++j){
    		cout << poi[j][i] << "  ";
    	}
    }
    cout << " " << sum << endl;
   }
  return 0;
}