N, H, M, T = [int(i) for i in input().split()] t = 60 * H + M + (N - 1) * T h, m = (t // 60) % 24, t % 60 print(h, m)