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