Problem I
Problem I
In this problem, you are given two positive integers, and followed by numbers . Using four basic arithmetic operations (addition, subtraction, multiplication and division(use floor to reach an integer)) and only the given numbers, convert into . For instance suppose and and the numbers are given to you. Two different ways to convert to are as follow: 1. First multiply by , then add to the result for two times. 2. Add to , times. There is just one more point that you should consider; different arithmetic operations have different costs. These costs are represented as a table, in which the cell ( ),( ) ( ) ( ) of this table contains the cost of addition, subtraction, multiplication and division with as a second operand respectively. You should find the minimum cost to convert to such that you never reach a number more than and less than zero.
Input
The number of test cases comes in the first line. For each test case, first there are three integer and . Then you are given positive integer . Finally, in the last lines in each line there are positive integer that represent cost of operations.
Output
For each test case, print the minimum cost to convert to . Sample Input
1 45 768 3 6 2 12 1 2 3 4 1 2 3 4 4 3 2 1 7
to
Sample Output