t,h,m,s = map(int,input().split()) if t>1: for i in range(t-1): m += s if m>=59: h+=m//60 m%=60 if h>=24: h%=24 print(h) print(m)