n, h, m, t = map(int, input().split()) alarm = h * 60 + m alarm = alarm + (n - 1) * t if alarm >= 1440: print(alarm // 60 // 24) print(alarm % 60) else: print(alarm // 60) print(alarm % 60)