#P10823. [EC Final 2020] Prof. Pang Earning Aus

[EC Final 2020] Prof. Pang Earning Aus

题目描述

Prof. Pang has only 11 Au in his pocket. (Yes, Prof. Pang is from Austan and he uses the currency Au there.)

He will make use of a balloon store and a candy store to make money: In the balloon store, Prof. Pang can buy kabk_{ab} balloons for the price of 11 Au or buy kcbk_{cb} balloons for the price of 11 candy. In the candy store, Prof. Pang can buy kack_{ac} candies for the price of 11 Au or buy kbck_{bc} candies for the price of 11 balloon. Prof. Pang can also sell one balloon and get kbak_{ba} Aus. He can sell one candy and get kcak_{ca} Aus. The only constraint to him is that there are only nbn_b balloons in the balloon store and only ncn_c candies in the candy store. He can buy balloons and candies only when supplies last. Even if he sells some of his balloons or candies, the number of balloons and candies in the stores will not increase.

Each of the six transactions can be performed in any order for any times (00 or more) but they are not separable (for example, Prof. Pang can not buy kab/2k_{ab}/2 balloons for the price of 1/21/2 Au).

Please find out how many Aus he can make at most.

输入格式

The first line contains a single integer TT (1T10001\le T\le 1000) denoting the number of test cases.

Each of the next TT lines contains eight integers nbn_b, ncn_c, kabk_{ab}, kbak_{ba}, kack_{ac}, kcak_{ca}, kbck_{bc}, kcbk_{cb} (1nb,nc1091\le n_b, n_c\le 10^9, $1\le k_{ab}, k_{ba}, k_{ac}, k_{ca}, k_{bc}, k_{cb}\le 100$) separated by single spaces.

输出格式

For each test case, print one line containing the answer.

6
2 2 2 2 2 2 2 2
78 74 5 3 10 2 4 7
31 75 3 6 6 1 8 4
91 86 4 2 9 5 8 5
48 89 3 9 2 3 5 7
13 25 5 7 6 1 2 4
7
355
239
571
637
109

提示

In the first example, Prof. Pang buys 22 balloons with 11 Au and then sells 22 balloons and gets 44 Aus. Then he buys 22 candies with 11 Au, sells 22 candies and gets 44 Aus.