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