N,H,M,T=map(int,input().split()) d=(N-1)*T H+=(d//60)%24 M+=d%60 if M==60: H+=1 M=0 H=0 if H==24 else H print(H) print(M)