N,H,M,T=map(int,input().split()) d=(N-1)*T h=(H+d//60)%24 M+=d%60 if M>=60: h+=1 M-=60 h=0 if h==24 else h print(h) print(M)