n,h,m,t=map(int,input().split()) time=h*60+m for i in range(n-1): time+=t print(time//60%24) print(time%60)