Voting Cities
문제
The great Emperor, Lord Pooty, decided to retire and would like to hand over the crown to one of his many sons. In the spirit of democracy, he decided to do this with a vote! His kingdom consists of cities labelled from to . Of these cities, of them are voting cities where voting can be done. The th voting city is .
As a reponsible member of society, you decided that it is only right for you to do your civic duty. You are to travel to one of the designated voting cities to vote! There are roads that can be used. Road connects city to city in one direction and has a toll of . Luckily, due to this event, local cities have opened a ticket system to reduce the cost of traveling.
There are different types of tickets to choose from, numbered from type to type . A ticket of type will reduce the cost of the toll on a road by . In other words, the cost of the road will be multiplied by if a ticket of type is used.
However, there are a few rules regarding the tickets. You cannot use more than one ticket on one road to stack the effects. You are only allowed to buy at most one of each ticket at the start of your journey. For example, you can choose to buy one type ticket and one type ticket but are not allowed to buy two type tickets. This is to prevent people from hoarding the tickets. You are only allowed to buy the tickets at the start of your journey.
You are a busy man and unfortunately, you do not know which city you may start your journey from, nor do you know the ticket prices. You have made a list of possible situations, comprised of a starting city and ticket prices , , , and for the tickets. It is possible that a certain ticket may not even be available, and in that case the ticket price will be .
For each of these situations, find the minimum cost to one of the voting city if it is reachable by road. Do note that not every city is reachable from every other and you may have to walk..
입력
Your program must read from standard input.
The first line of input contains integers , and representing the number of cities, number of roads and number of voting cities respectively. The second line contains integers, the th one representing , the th voting city.
The next contain integers each. The th of these lines consists of , and respectively, representing a unidirectional road from to with cost . It is guaranteed that is divisible by .
The next line contains a single integer , representing the number of situations to be considered.
The next lines contain integers , , , , and representing the starting city and the prices of the tickets of type to type respectively. Note that the starting city and ticket prices can differ across the different situations provided.
출력
Your program must print to standard output.
Output lines with integer on each line, representing the lowest cost to a voting city for each situation in the order provided in the input. If a path does not exist for a situation, print instead.
예제
예제 1
3 2 1 2 0 1 100 1 2 200 1 0 10 20 1000 2000 -1
280
예제 2
2 0 1 1 1 0 -1 -1 -1 -1 -1
-1
예제 3
6 3 2 4 5 0 4 100 1 4 200 2 5 300 4 0 -1 -1 -1 -1 -1 1 20 40 10 100 4 2 1 2 3 4 0 3 0 -1 0 0 0
100 104 150 -1