N,H,M,T = map(int,raw_input().split()) h,M = divmod(M+T*(N-1),60) print "%d\n%d" % ((H+h)%24,M)