n, h, m, t = map(int,input().split()) #起床時間を分換算 h_m = h * 60 al_time = h_m + m wakeup_time = al_time + (n-1)*t #起床時刻の計算:#時##分 wakeup_hour = wakeup_time//60 wakeup_time = wakeup_time%60 print(wakeup_hour) print(wakeup_time)