main = do [n, h, m, t] <- getLine >>= return . map read . words mapM_ putStrLn $ (\x -> [show(x`div`60),show(x`mod`60)]) $ (h * 60 + m + t * (n - 1)) `mod` (24 * 60)