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