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