n, h, m ,t = map(int, input().split()) late = (n - 1) * t lh = (h + (m + late) // 60) % 24 lm = (m + late) % 60 print(lh) print(lm)