import datetime n, h, m, t = map(int, input().split()) time = datetime.datetime.combine(datetime.date.today(), datetime.time(h, m)) time += datetime.timedelta(minutes=t*(n-1)) print(time.hour) print(time.minute)