N, H, M, T = map(int, input().split()) losstime = (N - 1) * T H += (losstime + M) // 60 while H > 23: H -= 24 M = (losstime + M) % 60 print(H) print(M)