import Control.Monad
import Control.Applicative

main = do
    n <- readLn
    if n == 0 then return ()
              else showMatrixSum n >> main

showMatrixSum :: Int -> IO ()
showMatrixSum n = do
    sets <- replicateM n $ map read.words<$>getLine :: IO [[Int]]
    let result = calcColmnSum.calcRawSum $ sets
    showMatrix 5 result

showMatrix :: Show a => Int -> [[a]] -> IO ()
showMatrix i list = putStr res
    where res = unlines.map (unwords.map (justifyr i.show)) $ list

justifyr :: Int -> String -> String
justifyr n str
  | length str < n  = replicate (n - length str) ' ' ++ str
  | otherwise       = str

calcRawSum :: Num a => [[a]] -> [[a]]
calcRawSum []       = []
calcRawSum (ns:nss) = (ns ++ [sum ns]) : calcRawSum nss

calcColmnSum :: Num a => [[a]] -> [[a]]
calcColmnSum list = list ++ [calc' list]
    where calc' = foldl (zipWith (+)) (replicate n 0) 
          n     = length.head $ list