import math n,h,m,t=map(int,input().split()) m+=(n-1)*t hup=math.floor(m/60) m-=hup*60 h+=hup dup=math.floor(h/24) h-=dup*24 print(h) print(m)