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