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