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