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