Full Tank#6221

Full Tank

1 second
64 megabytes
Hard

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 (1 \leq n \leq 1000) and (0 \leq m \leq 10000) - the number of cities and roads. Then follows a line with integers p_i (1 \leq p_i \leq 100), where p_i is the fuel price in the -th city. Then follow lines with three integers , (0 \leq u, v < n) and (1 \leq d \leq 100), telling that there is a road between and with length . Then comes a line with the number (1 \leq q \leq 100), giving the number of queries, and lines with three integers (1 \leq c \leq 100), and , where is the fuel capacity of the vehicle, is the starting city, and is the goal.

Output

For each query, output the price of the cheapest trip from to using a car with the given capacity, or impossible if there is no way of getting from to with the given car.

Examples

Example 1

Loading
Loading