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