n,h,m,t=gets.split.map(&:to_i) o=Time::utc(1,1,1,h,m)+(n-1)*t*60 p o.hour,o.min