let () = let n, h, m, t = Scanf.scanf "%d %d %d %d " (fun n h m t -> n, h, m, t) in let m = m + (n - 1) * t in let c, m = m / 60, m mod 60 in let h = (h + c) mod 24 in Printf.printf "%d\n%d\n" h m