N, H, M, T = map(int,input().split(' ')) A = M + T * (N - 1) if A < 60: print(H) print(A) elif A >= 60 and H + A // 60 < 24: H = H + A // 60 A = A % 60 print(H) print(A) elif A >= 60 and H + A // 60 >= 24: H = H + A // 60 A = A % 60 print(H - 24 * H // 24) print(A)