import datetime N, H, M, T = [int(i) for i in input().split()] first_alarm = datetime.datetime(1970, 1, 1, H, M) wake_up = first_alarm + datetime.timedelta(minutes=T*(N-1)) print(wake_up.hour, wake_up.minute, sep="\n")