#arc139b. [arc139_b]Make N

[arc139_b]Make N

Problem Statement

We have an integer P=0P=0. Find the minimum total cost to make P=NP=N by doing the following three kinds of operations any number of times in any order.

  • Increase PP by 11, at a cost of XX.
  • Increase PP by AA, at a cost of YY.
  • Increase PP by BB, at a cost of ZZ.

Solve each of the TT test cases given to you.

Constraints

  • 1leTle1001 \\le T \\le 100
  • 1leN,A,B,X,Y,Zle1091 \\le N,A,B,X,Y,Z \\le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

TT mathrmcase1\\mathrm{case}_1 mathrmcase2\\mathrm{case}_2 vdots\\vdots mathrmcaseT\\mathrm{case}_T

Each test case is in the following format:

NABXYZN\\ A\\ B\\ X\\ Y\\ Z

Output

Print TT lines, the ii-th of which should contain the answer to mathrmcasei\\mathrm{case}_i.


Sample Input 1

5
10 3 5 2 3 6
10 3 5 1 1000000000 1000000000
139 2 139 1 1 1
139 1 1 1 1 1
139 7 10 3845 26982 30923

Sample Output 1

11
10
1
139
436604

In the first test case, below is one way to make P=10P=10 at the cost of 1111, which is optimal.

  • Increase PP by 33, making P=3P=3, at a cost of 33.
  • Increase PP by 11, making P=4P=4, at a cost of 22.
  • Increase PP by 33, making P=7P=7, at a cost of 33.
  • Increase PP by 33, making P=10P=10, at a cost of 33.