import datetime N , H , M , T = map(int , input().split()) first_ring = datetime.time(H , M) wake_up = datetime.datetime.combine(datetime.date(2019,5,26), first_ring) + datetime.timedelta(minutes=(N-1)*T) print(wake_up.hour) print(wake_up.minute)