{"raw_statement":[{"iden":"problem statement","content":"We have an integer $P=0$. Find the minimum total cost to make $P=N$ by doing the following three kinds of operations any number of times in any order.\n\n*   Increase $P$ by $1$, at a cost of $X$.\n*   Increase $P$ by $A$, at a cost of $Y$.\n*   Increase $P$ by $B$, at a cost of $Z$.\n\nSolve each of the $T$ test cases given to you."},{"iden":"constraints","content":"*   $1 \\le T \\le 100$\n*   $1 \\le N,A,B,X,Y,Z \\le 10^9$\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$T$\n$\\mathrm{case}_1$\n$\\mathrm{case}_2$\n$\\vdots$\n$\\mathrm{case}_T$\n\nEach test case is in the following format:\n\n$N\\ A\\ B\\ X\\ Y\\ Z$"},{"iden":"sample input 1","content":"5\n10 3 5 2 3 6\n10 3 5 1 1000000000 1000000000\n139 2 139 1 1 1\n139 1 1 1 1 1\n139 7 10 3845 26982 30923"},{"iden":"sample output 1","content":"11\n10\n1\n139\n436604\n\nIn the first test case, below is one way to make $P=10$ at the cost of $11$, which is optimal.\n\n*   Increase $P$ by $3$, making $P=3$, at a cost of $3$.\n*   Increase $P$ by $1$, making $P=4$, at a cost of $2$.\n*   Increase $P$ by $3$, making $P=7$, at a cost of $3$.\n*   Increase $P$ by $3$, making $P=10$, at a cost of $3$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}