Virtual Rabbit (Large)

Find the fewest feedings over D days so no gap exceeds X seconds while skipping work and sleep hours.

Medium7GreedyMathIntervalsNo attempts yetTime limit5sMemory limit512 MB

Problem

Alice just bought a virtual pet rabbit. The rabbit hops around on a screen, and pressing a button feeds it. Alice is fond of the rabbit, but she is also busy and does not want to spend much time taking care of it. If the rabbit goes without food for too long it dies, and Alice loses the game.

Every day Alice gets up at time GG, leaves for work at time WW, comes home at time HH, and goes to bed at time BB. She cannot feed the rabbit while she is at work or asleep, that is, during the intervals [W,H)[W, H) and [B,G)[B, G). The seconds WW and BB are not valid feeding times, while the seconds HH and GG are. In every other second Alice either presses the button, which feeds the rabbit instantly, or does nothing. Between every two consecutive seconds the rabbit counts how many seconds in a row it has gone without food, and it dies at the moment that count equals XX. The gap between two consecutive feedings is therefore at most XX seconds.

It is now 00:00:00 on day 0, and the mail carrier has just delivered the rabbit to Alice's house. The carrier presses the button at 00:00:00 even if Alice is asleep, and then leaves. That press is not counted as one of Alice's feedings. Alice wants the rabbit to still be alive at 00:00:00 on day DD. By the same rule, the gap between the last feeding and 00:00:00 on day DD must not exceed XX seconds either. Find the smallest number of times Alice has to feed the rabbit, if she can keep it alive at all.

Input

The first line holds the number of test cases TT. The TT test cases follow, each of them 6 lines long. The first 5 lines hold the times GG, WW, HH, BB and XX in "hh:mm:ss" format. The last line holds one integer DD.

Limits

  • 1T1001 \le T \le 100.
  • Alice always goes to bed before midnight and gets up at or after midnight, so GG, WW, HH and BB increase strictly within the same day.
  • 00:00:00G<W<H<B23:59:59\text{00:00:00} \le G < W < H < B \le \text{23:59:59}.
  • 00:00:00<X23:59:59\text{00:00:00} < X \le \text{23:59:59}.
  • 1D10141 \le D \le 10^{14}.

Output

For each test case print one line of the form "Case #x: y", where x is the test case number starting from 1 and y is the smallest number of times Alice needs to feed the rabbit. If the rabbit cannot be alive at 00:00:00 on day DD, print -1 in place of y.

Hint

In the first case of the example, Alice can feed the rabbit at 08:00:00 and 20:00:00 every day. In the second case the rabbit dies before Alice even wakes up on day 0.