solve [n, h, m, t] = uncurry (\a b -> [mod (h + a) 24, b]) $ flip divMod 60 (m + (n - 1) * t) main = getLine >>= mapM_ print . solve . map read . words