module Main where main :: IO () main = do { [n,h,m,t] <- getInts ; case norm (h,m+t*(n-1)) of (h',m') -> print h' >> print m' } norm :: (Int, Int) -> (Int, Int) norm (h,m) = case divMod m 60 of (h',m') -> ((h+h') `mod` 24, m') getInts :: IO [Int] getInts = map read . words <$> getLine