def main(): N, H, M, T = map(int, input().split()) h, m = divmod(M + (N - 1) * T, 60) h += H if h >= 24: h = h % 24 print(h) print(m) main()