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