n,h,m,t=map(int,raw_input().split()) m+=t*n-t print(h+m/60)%24 print m%60