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