N, H, M, T = map(int, input().split()) sleep_minutes = T * (N - 1) + M q, mod = divmod(sleep_minutes, 60) print((H + q) % 24) print(mod)