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