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