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