Getting There 

A frustrating part of arranging your own air travel trip is selecting from among many possible flights that sequence of flights which will take you from your origin to your destination in the least possible time or for the least possible cost.

It should be clear to any frequent air passenger that in order to reach one city from another, the cost of the shorter flight may be more than the cost of longer flights. In other words, it may pay you well to cool your heels in an airport waiting for a connecting flight rather than take a more direct flight or one in which the connecting time is shorter. For example, consider the following flight schedule.

            CenterCity      Homeville       5:20A  6:55A  12.50
            CenterCity      Greenville      5:45A  9:15A  35.00
            Homeville       Greenville      7:45A  9:35A  20.00

In order to travel from CenterCity to Homeville, you have two choices. You can travel from Centerity to Homeville, then from Homeville to Greenville, or you can travel directly from Centerity to Greenville. The first route costs $32.50 and has travel time 4:15; the direct route costs $35.00 and has travel time 3:30. If minimizing cost is your objective, then you would choose the first route. If you want to minimize time, you would select the second route.

You are to write a program to optimize route selection given the criteria of least cost or least time. Your program will read a list of flights and several trip requests and will select from the list of flights the best sequence to satisfy each trip request. For each request, if more than one route should satisfy the request, then your program should select the route that also satisfies the other objective. For example, if cost is to be minimized and if two routes both yield the minimum cost, then select the route which yields the shortest travel time. There is only one valid solution for each input in the data set.

Input

The input data will consist of various test cases. Each case begins with line TRAVEL XXX, where XXX is ID number of the travel. ID number is a positive integer with leading zeroes. There will be less than 100 tests. Each test is broken into two segments, the first describing the list of flights and the last containing the trip requests. The end of each part of the test is indicated by the line consisting of the single character `#'.

The flight segment of the test describes individual flights, one per line. Each line contains the origin city (begins from column 1), the destination city (begins from column 18), the departure time (begins from column 34). the arrival time (begins from column 42), and the cost (columns 52 through 62). City names are left-justified in their respective fields, and may only contain upper and lower case characters. City names like CITY and cItY are same and lengths of city names will be less than 17 symbols. Times are in the form HH:MMX, where HH is the hour (a leading zero may be replaced by a blank), MM is the minutes (exactly two digits will appear), and X is A (for AM), P (for PM). The cost of the ticket is in dollars and cents, and includes a decimal point and two fractional digits. No tickets are free or cost more than $999.99. Departure times are always prior to arrival times. All individual flights represented by a line in the schedule take less than 24 hours. There will be at most 50 flights and at most 20 cities on the schedule. There will be no unnecessary blanks and spaces in the first part of a test.

The trip request segment of the file immediately follows the list of flights. Each request appears on a line by itself, and specifies the origin city, the destination city, and whether to optimize cost or travel time. If it is desired to optimize travel time, the word TIME is displayed. If cost is to be optimized, then the word COST is displayed. There may be leading and trailing blanks in any line in the trip requests. The end-of-file indicates the end of the input file.

Output

For the first line of each test display "Requests and optimal routes for travel Y" without quotes where Y is an ID number of the test shown in the input and must be without leading zeroes.

You can find all cases of the output format in the sample output and your output must be identical. All optimum routes will require less than 10 days and less than $1,000.00. Place one blank line between the outputs for successive trips and two blank lines between successive tests.

Sample Input

TRAVEL 001
CenterCity       Homeville       5:20A   06:55A    12.50
CenterCity       Greenville      5:45A   9:15A     35.00
Homeville        Greenville      07:45A  9:35A     20.00
ArcherCity       Homeville       5:00A   6:00P     612.50
#
CenterCity       Greenville      COST
ArcherCity       Greenville      TIME
#
TRAVEL 992
GreenVille       Greenmile       10:30A  11:30A    5.00
GreenMile        GreenYARD       0:30P   3:00P     0.51
AA               BB              1:00A   1:01A     0.01
ZZZ              ZZZZ            0:03A   0:02A     0.50
ZZZZ             ZZZZZ           0:02A   0:01A     0.50
ZZZZZ            ZZZZZZ          0:01A   0:00A     0.50
#
GREENVILLE       GreeNVILLE      COST     
Greenville  Greenmile                  TIME       
GreenMile    GreenYard    TIME   
AA    Greenville          TIME
ZZZ ZZZZZZ TIME
#

Sample Output

Requests and optimal routes for travel 1
------------------------------------------

From: Centercity           To: Greenville           Optimize: Cost
==================================================================
From                To                     Leave   Arrive     Cost
==================================================================
Centercity          Homeville              5:20A   6:55A    $12.50
Homeville           Greenville             7:45A   9:35A    $20.00
                                           -----------------------
                                                     4:15   $32.50

From: Archercity           To: Greenville           Optimize: Time
==================================================================
From                To                     Leave   Arrive     Cost
==================================================================
Archercity          Homeville              5:00A   6:00P   $612.50
Homeville           Greenville             7:45A   9:35A    $20.00
                                           -----------------------
                                               1 day 4:35  $632.50


Requests and optimal routes for travel 992
------------------------------------------

You are already in Greenville.

From: Greenville           To: Greenmile            Optimize: Time
==================================================================
From                To                     Leave   Arrive     Cost
==================================================================
Greenville          Greenmile              10:30A  11:30A    $5.00
                                           -----------------------
                                                     1:00    $5.00

From: Greenmile            To: Greenyard            Optimize: Time
==================================================================
From                To                     Leave   Arrive     Cost
==================================================================
Greenmile           Greenyard              0:30P   3:00P     $0.51
                                           -----------------------
                                                     2:30    $0.51

There is no route from Aa to Greenville.

From: Zzz                  To: Zzzzzz               Optimize: Time
==================================================================
From                To                     Leave   Arrive     Cost
==================================================================
Zzz                 Zzzz                   0:03A   0:02A     $0.50
Zzzz                Zzzzz                  0:02A   0:01A     $0.50
Zzzzz               Zzzzzz                 0:01A   0:00A     $0.50
                                           -----------------------
                                             2 days 23:57    $1.50