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