import math N, H, M, T = map(int, input().split()) wm = M + T * (N - 1) wh = (H + math.floor(wm / 60)) % 24 wm = wm % 60 print(wh) print(wm)