logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:256 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Prof. Pang has only 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 balloons for the price of Au or buy balloons for the price of candy. In the candy store, Prof. Pang can buy candies for the price of Au or buy candies for the price of balloon. Prof. Pang can also sell one balloon and get Aus. He can sell one candy and get Aus. The only constraint to him is that there are only balloons in the balloon store and only 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 ( or more) but they are not separable (for example, Prof. Pang can not buy balloons for the price of Au).

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

输入格式

The first line contains a single integer () denoting the number of test cases.

Each of the next lines contains eight integers , , , , , , , (, ) separated by single spaces.

输出格式

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

样例

样例输入 1

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

样例输出 1

7
355
239
571
637
109

数据范围与提示

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