n,h,m,t=map(int,input().split()) n-=1 time=h*60+m time+=t*n ansh=(time//60)%24 ansm=time%24 print(ansh) print(ansm)