def main(): n, h, m, t = [int(i) for i in input().split()] additional_sleeping_min = (n - 1) * t ans_min = m + additional_sleeping_min if ans_min > 60: plus_hour = int(ans_min / 60) m = ans_min % 60 ans_min += plus_hour if h > 24: h = h % 24 print(h) print(ans_min) if __name__ == '__main__': main()