n,h,m,t=map(int,input().split()) u=~-n*t+m print((h+u%60)%24) print(u%60)