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