SOLVE
LATER
Our friend Satyaki has finally opened up his new Toy Shop. Satyaki can't resist himself from sharing this news with everyone. He has been promoting his new shop throughout the town. He keeps dreaming about the profit he would make out of his new shop.
His shop currently has 3 types of balls. All the 3 types of balls have the exact same shape and size but they differ only in colour. So the colour of these 3 types are:
Ball Type1 :- Red Colour
Ball Type2 :- Green Colour
Ball Type3 :- Blue Colour.
Using these 3 types of ball, Satyaki's shop currently produces 3 types of toys. The balls required for the production of each type of toy is different. The composition to produce each Type of Toy is as follows:
Type1 Toy : 1 Ball of Type1 + 1 Ball of Type2
Type2 Toy : 1 Ball of Type2 + 1 Ball of Type3
Type3 Toy : 1 Ball of Type1 + 1 Ball of Type2 + 1 Ball of Type3
Satyaki sells a single unit of Type1 Toy at P$, a single unit of Type2 Toy at Q$ and a single unit of Type3 Toy at R$. He also sells the Ball he initially had, a single unit of each Type of ball is sold at S$.
Satyaki's shop initially has X Balls of Type1, Y Balls of Type2 and Z Balls of Type3.
Satyaki is a shrewd businessman. He wants to maximize his profit as much as he can. But he sucks at solving complex problems. So he asks you for help. Tell him the maximum amount of profit he can make.
Input Format :
The first line line contains an integer T denoting the number of testcases. Each testcase contains the following inputs.
The first line of each test case contains 3 space separated integers that are X, Y and Z. (Count of each ball type).
This is followed up by a line contains 4 space separated integers that are P, Q, R and S(price of each Toy Type and Ball Type respectively).
Output Format:
For each test case output 1 integer that is the maximum amount of profit Satyaki could make.
Constraints :
1 <= T <= \(10\)
1 <= X,Y,Z <= \(1000\)
1<= P,Q,R,S <= \(10^9\)
Case 1:
He could make 2 units of Type1 Toy, 1 unit of Type2 Toy and sell the leftover Type3 Ball. Profit= 17*2+9+3 = 46
Case 2:
Similar as Case 1.