By Gabriel Duarte, UNIFESO Brazil
As you all know, the mayoral elections are coming. This year our city has excellent candidates, all with incredible government proposals.
One candidate intends to implement a revolutionary transport system, where the streets will be removed and exchanged for bike lanes. This idea seems to be the solution to all the problems that our city is facing. But there is a flaw: dehydration when we walk long time in a bike.
To solve this problem, the applicant intends to provide chilled water for the entire population. His idea is to place distribution points in all intersections of the bike lane. But as water is a resource that is running out, the amount that it will provide will be fixed, regardless of the distance traveled by the individual.
Intending to validate your idea, the candidate hired you to help. Your task is simple: will be provided the city map with all the intersections and the distances between them. Then you must answer several candidate queries, where it will provide two intersections, A and B, and your program will show what the greatest distance to be traveled by a person without water between A and B. With this information the candidate able see if the amount that it intends to provide will suffice. Do not forget that the candidate intends to reduce this distance, then your program should inform the greatest distance in the best way.
As the streets of our city are very wide, all bike lanes will be two-way.
The entrance has several test cases. Each test case begins with two integers N (1 ≤ N ≤ 100) and M (1 ≤ M ≤ 4950), respectively indicating the number of intersections in the city map and how many bike lanes will be created. In the next M lines will be provided three integers U, V (1 ≤ U, V ≤ N) and W (0 ≤ W ≤ 2000), indicating that there is a bike lane between the U and V intersect wiht a distance W. The next line will have an integer Q (1 ≤ Q ≤ 50), which represents the number of queries that the candidate wants to do. Here Q lines with two integers A and B (1 ≤ A, B ≤ N) indicating the pair of intersections for which the query must be made. The entry ends when N = M = 0 and should not be processed.
|Input Sample||Output Sample|