import datetime n, h, m, t = map(int, input().split()) begin = datetime.datetime(2019, 1, 1, h, m) between = datetime.timedelta(0, 60 * t) up = begin + between * (n - 1) print(up.hour) print(up.minute)