n,h,m,t = map(int,raw_input().split()) next_hour = t/60 next_min = t%60 if n == 1: print(h) print(m) else: for i in range(n-1): h=h+next_hour m=m+next_min if 1 <= m/60: h=h+m/60 m=m%60 if 24 <= h: while(h<=23): h=h-24 print(h) print(m)