Pusheen has been dreaming about tuna sashimi! She has decided that she needs to eat more tuna in her life, so she decides to go on a tuna tour to eat tuna sashimi and tuna nigiri!
Pusheen has made a note of restaurants serving tuna sashimi and tuna nigiri and has made plans to eat at many of them! She has trips planned - on trip , she will start by eating lunch at restaurant and then walk over to restaurant for dinner.
The restaurants are connected by bidirectional roads that Pusheen can walk along in either direction. Pusheen is excited to eat as much tuna sashimi and tuna nigiri as possible, so she wants to know the length of the shortest path between each of these restaurants. Pusheen will not need her helicopter for this, as it is guaranteed that she can walk from any restaurant to any other restaurant along these roads.
Constraints
,
There will be at most one road between two restaurants.
It is possible to reach any restaurant from any other restaurant via the given roads.
,
Input Specification
The first line contains two space-separated positive integers, and .
lines follow, each containing three space-separated positive integers, , , and , indicating a bidirectional road of length between restaurants and .
A single line follows with a single positive integer, .
lines follow, each containing two space-separated positive integers, and , indicating that Pusheen's th trip will be between restaurants and .
Output Specification
Output lines. On the th line, compute the length of the shortest path for Pusheen's th trip.
Sample Input
3 3
1 2 1
2 3 2
1 3 4
2
1 2
1 3
Sample Output
1
3
Comments