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