Virtual Rabbit (Small)
Time limit5sMemory limit512 MB
Feed a pet at allowed times of day so no gap between feedings exceeds X seconds, using as few feedings as possible.
Problem
Alice just bought a virtual pet rabbit. The rabbit hops around on the screen and eats on the spot whenever she presses a button. Alice is fond of the rabbit, but she is 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 , leaves for work at time , comes back home at time , and goes to bed at time . She cannot feed the rabbit while she is at work or asleep, that is, during the intervals and . The times and are not valid feeding times, while the times and are. In every other second Alice either presses the button and feeds the rabbit instantly, or does nothing.
The rabbit dies once more than seconds have passed since it last ate.
It is now 00:00:00 on day 0, and the mail carrier has just delivered the rabbit. The carrier presses the button at 00:00:00 even though Alice is asleep, and then leaves. Alice wants the rabbit to be alive at 00:00:00 on day . If she can keep it alive, how few times can she feed it?
Stated precisely: number every second from 0, so that 00:00:00 on day 0 is second 0 and 00:00:00 on day is second . Let be the seconds at which Alice feeds the rabbit, and let be the moment the mail carrier pressed the button. The rabbit is alive at 00:00:00 on day exactly when both conditions hold.
- for every with
Every with must be a second whose time of day falls in or in . Find the smallest possible .
Input
The first line contains the number of test cases . Then test cases follow, each consisting of 6 lines. The first five lines give the times , , , and the length in "hh:mm:ss" format, one per line. The last line contains one integer .
Limits
- Alice always goes to bed before midnight and gets up after midnight, so , , and increase strictly within the same day.
Output
For each test case print one line in the format "Case #x: y", where is the test case number starting from 1 and is the minimum number of times Alice has to feed the rabbit. If there is no way to keep the rabbit alive at 00:00:00 on day , then is .
Hint
In the first test case of the example, Alice can feed the rabbit at 08:00:00 and at 20:00:00 every day.
In the second test case of the example, the rabbit dies before Alice even wakes up on day 0.