a,b,c,d=map(int,input().split()) N=c+(a-1)*d if b+N//60>=24: print((b+N//60)%24) print(N%60) else: print(b+N//60) print(N%60)