import Data.List
main = interact $ unlines . map (unwords . map show) . itp1_7_c . map (map read . words) . tail . lines
itp1_7_c = transpose . map addsum . transpose . map addsum
 where addsum ns = ns ++ [sum ns]