n, h, m, t = map(int,input().split()) #起床時間を分換算 h_m = h * 60 al_time = h_m + m #1日以上寝る場合考慮,%1440分 wakeup_time = (al_time + (n-1)*t)%1440 #起床時刻の計算:#時##分 wakeup_hour = wakeup_time//60 wakeup_time = wakeup_time%60 print(wakeup_hour) print(wakeup_time)