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>=1: h-=h//24*24 print(h) print(m)