cho.sh
Notes
Loading...

Ferries

Time limit

2s

Memory limit

128 MB

Problem

In Norway, land and fjords alternate along many routes. To travel from the start to the destination, you drive on land sections and use scheduled ferries to cross fjord sections.

The fastest strategy is to drive on every road section at the maximum speed of 80 km/h, wait for the earliest ferry you can board at each fjord, and repeat this process. Driving that fast is expensive and not environmentally friendly, so you must first find the minimum possible total travel time, and then find the lowest constant driving speed that can still achieve that same minimum time.

Input

The input contains several data sets. The first line of each data set contains an integer s (s > 0), the number of route sections. The next s lines describe the sections in the order traveled. Each line starts with the names of the start location and end location, followed by the section type.

A road section has the form start end road length. The value length is a positive integer distance in kilometers.

A ferry section has the form start end ferry crossing f minute1 ... minutef. The value crossing is the crossing time in minutes, and f (f > 0) is the number of ferry departures in each hour. The following f integers are the departure minutes within an hour, given in increasing order. The same schedule repeats every hour.

Every data set is designed so that the total travel time is at most 10 hours. Travel always starts exactly on an hour, at time x:00. A line containing 0 ends the input.

Output

For each data set, output one line containing the data set number, the minimum total travel time, and the minimum driving speed that still achieves that travel time. Use the format Test Case k: HH:MM:SS v. Round the speed to two digits after the decimal point.