import datetime yuki_list = list(map(int, input().split())) n = yuki_list[0] h = yuki_list[1] m = yuki_list[2] t = yuki_list[3] up_f = datetime.date(2019,1,1,h,m) sleep_time = (n-1) * t delta = datetime.timedelta(minutes=sleep_time) up_s = up_f + delta print(up_s.hour) print(up_s.minute)