main :: IO ()
main = interact $ unlines . map (unwords . map show) . calc . map (map read . words) . tail . lines

calc :: [[Int]] -> [[Int]]
calc = addVSum . map addHSum
    where addHSum xs  = xs ++ [sum xs]
          addVSum xss = xss ++ [foldr1 (zipWith (+)) xss]
