Full Tank
After going through the receipts from your car trip through Europe this summer, you realised that the gas prices varied between the cities you visited. Maybe you could have saved some money if you were a bit more clever about where you filled your fuel?
To help other tourists (and save money yourself next time), you want to write a program for finding the cheapest way to travel between cities, filling your tank on the way. We assume that all cars use one unit of fuel per unit of distance, and start with an empty gas tank.
Input
The first line gives n (1 ≤ n ≤ 1000) and m (0 ≤ m ≤ 10000) - the number of cities and roads. Then follows a line with n integers p_i (1 ≤ p_i ≤ 100), where p_i is the fuel price in the i-th city. Then follow m lines with three integers u, v (0 ≤ u, v < n) and d (1 ≤ d ≤ 100), telling that there is a road between u and v with length d. Then comes a line with the number q (1 ≤ q ≤ 100), giving the number of queries, and q lines with three integers c (1 ≤ c ≤ 100), s and e, where c is the fuel capacity of the vehicle, s is the starting city, and e is the goal.
Output
For each query, output the price of the cheapest trip from s to e using a car with the given capacity, or impossible if there is no way of getting from s to e with the given car.