import datetime N, H, M, T = map(int, input().split(' ')) dt = datetime.datetime(2019, 1, 1, H, M) dl = datetime.timedelta(minutes=T) t = (dt + dl * (N - 1)) print(t.hour) print(t.minute)