n,h,m,t=(int(i) for i in input().split()) new_m=(m+t*(n-1))%60 new_h=(h+(m+t*(n-1))//60)%24 print(new_h) print(new_m)