n, h, m, step = (int(i) for i in input().split()) over = (n - 1) * step if m + over > 59: print(h + 1) print(m - 60 + over) else: print(h) print(m + over)