import Data.List

type Row = [Int]
type Matrix = [Row]

main = getContents >>= putOut.formatOut.solve.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
  
formatIn :: String -> (Matrix,Matrix) 
formatIn = (\((n:_):xs) -> splitAt n xs).map (map (read :: String -> Int).words).lines

formatOut :: Matrix -> String
formatOut = unlines.map (unwords.(map show))

solve :: (Matrix,Matrix) -> Matrix
solve (xs, ys) = map (flip (\x -> map (sum.(zipWith (*) x))) $transpose ys) xs