n,h,m,t=map(int,input().split()) m+=t*(n-1) if m//60>=1: h+=m//60 m-=m//60*60 if h>=24: h-=24 print(h) print(m)