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