N, H, M, T = map(int, input().split())
t = H*60+M+T*(N-1)
print(t//60%24)
print(t%60)