This is not as easy as it seems. It often takes a knight several days to go
from the castle where he lives to the place where a tournament is held.
But horses sometimes are very, very stubborn. After having covered a certain distance
on a single day, they sometimes simply stop and refuse to go any further.
Luckily, they start anew on the next day. To make sure that the horse does not
refuse service before the scheduled day trip is completed, a knight wants to choose an
itinerary on which the longest day trip is as short as possible.
Hence, a trip that takes many days with short distances is preferable over a
shorter route that has the risk of a refusing horse.
Write a program which answers queries from knights spread all over the country about the best way to go from their castles to a tournament site. Given a description of the relevant places (i.e. castles, locations of tournaments, and hostels for overnight stays), the program should tell them the largest distance they have to cover on a single day so that this distance is minimal among all possible itineraries.
The places are designated by consecutive integers from 1 to , while a road is represented by three integers, namely its place of origin, its destination, and its length. Every road can be used in both directions, and there is at least one route (i.e. a sequence of roads) between any two places. The knights stick to the given roads while travelling and spend their nights only at one of the places.
Input
The first line contains the total number of test cases that follow.
Each test case begins with a line that first holds the number of places ( ) followed by the number of roads ( ). Then there are lines with three integers each ( , , and ), each of which defines a road connecting the places and ( ) with length ( ).
Thereafter, each test case continues with the number
of queries on a line by
itself (
). Each of the next
lines holds two integers
and
, indicating a query by a knight who lives at place
and
needs to go to a tournament at place
(
,
).
Output
For each test case output a line containing the word ``Case'', a single
space, and its serial number (starting with
for the first test case). Then,
print one line for each query in this test case, containing the smallest maximal day trip
distance as described above.
Print a blank line after each test case.
Sample Input
Sample Output