import datetime n,h,m,t=map(int,input().split()) dt1 = datetime.timedelta(hours= h, minutes=m) #time_1 = datetime.timedelta(hours= h, minutes=m, seconds=00) dt2 = dt1 + datetime.timedelta(minutes=t*(n-1)) dt3=dt2.days #print(dt3) dt4=dt2 - datetime.timedelta(days=dt3) #print(dt4) d=str(dt4) l=list(map(int,d.split(":"))) print(l[0]) print(l[1])