n,h,m,t=map(int,input().split()) if t>60: t%=60 if n==1: print(h,m,sep='\n') else: n-=1 t*=n m+=t while m>=60: m-=60 h+=1 while h>24: h-=24 print(h,m,sep='\n')