This page is still under construction.

Parts of this page are still being built. What you see may change.

Vice City

Interview

Time limit1sMemory limit128 MB

Summary
Find the fastest route from PayPhone to WKCharriot, where travel time depends on the vehicle you drive and each vehicle swap costs one minute.
Level

Medium6 of 10

Topics
Graph, Shortest path, Greedy, Implementation
Solved
No attempts yet

Problem

"Tommy, there will be a programming contest here in Vice City. One of the coaches has stolen a copy of the problem set. The chief judge wants it back. Take out the coach at his hotel and bring the problems back. The address is taped under the phone. Do it now!"

Not a tough job for you, Tommy Vercetti! After grabbing the mission at the pay phone, you must reach the coach at the WK Charriot Hotel before he leaves — and you must get there as fast as you possibly can. Unfortunately, the vehicle you start with may not be fast enough. Luckily, there are fixed locations around Vice City where a particular vehicle is always parked — for example, Diaz's Mansion, where an Infernus is waiting. So you may swap vehicles several times on the way to the hotel. Each time you change vehicles it costs you one minute.

You start at PayPhone already driving the vehicle parked there (this starting vehicle costs no change time), and your goal is WKCharriot. You are given the names of the locations in the city and the distances between connected pairs. At each location a specific vehicle is available whenever you arrive there. Knowing the top speed of every vehicle, find the minimum time needed to reach the hotel. For simplicity, assume you always drive at the top speed of your current vehicle, so travelling a road of length dd kilometers at speed ss km/h takes 60⋅d/s60 \cdot d / s minutes.

Input

The first line contains a single integer tt (1≤t≤201 \le t \le 20), the number of test cases. Each test case has three parts, and consecutive parts are separated by exactly one blank line.

The first part consists of mm lines (1≤m≤1001 \le m \le 100), each of the form vehicle speed, where vehicle is the unique name of a vehicle and speed is a positive integer giving its top speed in km/h.

The second part consists of nn lines (2≤n≤5002 \le n \le 500), each of the form location vehicle, where location is the unique name of a location and vehicle is the vehicle parked there. The list of locations always includes the starting location PayPhone and the destination WKCharriot.

The third part lists the roads, each of the form loc1 loc2 distance, meaning there is a two-way road of the given positive integer length (in kilometers) between loc1 and loc2. This part is terminated by a line containing a single asterisk (*).

All vehicle and location names are strings of at most 100 letters and digits with no spaces, and are case sensitive. Items on a line are separated by one or more spaces, and lines may have arbitrary leading or trailing blanks except for the empty separator lines.

Output

For each test case, print a single line with the minimum time, in minutes, to travel from PayPhone to WKCharriot, or the word UNREACHABLE if the destination cannot be reached from the start.

Print the time with exactly three digits after the decimal point. Any digits beyond the third are truncated (ignored, not rounded), and if fewer than three digits are present they are padded with zeros.

Examples1

  1. Example 1

    Input
    2
    
    Infernus     280
    Cheetah      285
    PCJ600       250
    Stallion     180
    HotRingRacer 300
    
    Mansion         Infernus
    CarShowRoom     HotRingRacer
    VicePort        Cheetah
    NorthPointMall  Infernus
    PayPhone        PCJ600
    WKCharriot      Stallion
    
    PayPhone       CarShowRoom    10
    PayPhone       VicePort       15
    VicePort       WKCharriot     20
    CarShowRoom    Mansion        15
    Mansion        WKCharriot     15
    Mansion        NorthPointMall 5
    NorthPointMall WKCharriot     5
    *
    Caddy        80
    MrWhoopie    60
    Stretch      120
    CubanHermes  160
    Voodoo       170
    
    CherryPoppy  MrWhoopie
    Mansion      Stretch
    PayPhone     CubanHermes
    LittleHaiti  Voodoo
    WKCharriot   Caddy
    
    PayPhone      CherryPoppy    10
    CherryPoppy   LittleHaiti    15
    Mansion       WKCharriot     20
    *
    
    Expected output
    8.400
    UNREACHABLE