#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n;
  while(cin>>n,n){
    vector<vector<int> > in(n+1,vector<int>(4,0));
    rep(i,n){
      rep(j,4){
	cin>>in[i][j];
	printf("%5d",in[i][j]);
	in[i][4] += in[i][j];
	in[n][j] += in[i][j];
      }
      printf("%5d\n",in[i][4]);
    }
    rep(j,4){
      printf("%5d",in[n][j]);
      in[n][4] += in[n][j];
    } 
    printf("%5d\n",in[n][4]);
  }

}