#ARC139B. [ARC139B] Make N

[ARC139B] Make N

Score : 500500 points

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

  • 1T1001 \le T \le 100
  • 1N,A,B,X,Y,Z1091 \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

case1\mathrm{case}_1

case2\mathrm{case}_2

\vdots

caseT\mathrm{case}_T

Each test case is in the following format:

N A B X Y ZN\ A\ B\ X\ Y\ Z

Output

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

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
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.