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