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