n,h,m,t = gets.split.map(&:to_i) s=(n-1)*t+m hs=h+s/60 puts n==1 ? [h,m] : s<60 ? [h,s] : hs>23 ? [hs%24,s%60] : [hs,s%60]