#include<cstdio>
int main()
{
    int n,hyo[11][11];
    while(scanf("%d",&n),n)
    {
        for(int i=0;i<n+1;i++)
        {
            hyo[n][i]=0;
            hyo[i][n]=0;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                scanf("%d",&hyo[i][j]);
                hyo[n][i]+=hyo[i][j];
                hyo[i][n]+=hyo[i][j];
            }
        }
        for(int i=0;i<n;i++)hyo[n][n]+=hyo[i][n];
        for(int i=0;i<n+1;i++)for(int j=0;j<n+1;j++)
        {
            if(hyo[i][j]%10==hyo[i][j])printf("    ");
            else if(hyo[i][j]%100==hyo[i][j])printf("   ");
            else if(hyo[i][j]%1000==hyo[i][j])printf("  ");
            else if(hyo[i][j]%10000==hyo[i][j])printf(" ");
            printf("%d",hyo[i][j]);
            if(j==n)printf("\n");
        }
    }
    return 0;
}