n,h,m,t=map(int,input().split()) a=(n-1)*t x=(m+a)%60 y=(h+(m+a)//60)%24 for i in [y,x]: print(i)