Prof. Pang Earning Aus
Time limit3sMemory limit1024 MB
Given two stores with balloon and candy stocks and six exchange rates, find the most Au Prof. Pang can earn starting from 1 Au.
- Level
Medium6 of 10
- Topics
- Greedy, Simulation, Math
- Solved
- No attempts yet
Problem
Prof. Pang has only Au in his pocket. (Yes, Prof. Pang is from Austan, and he uses the currency Au there.)
He makes money using a balloon store and a candy store. In the balloon store, Prof. Pang can pay Au to buy balloons, or pay candy to buy balloons. In the candy store, he can pay Au to buy candies, or pay balloon to buy candies. He can also sell one balloon for Au and sell one candy for Au. The balloon store has balloons, and the candy store has candies. He can buy only as many items as the stores have. Selling items does not increase the number of balloons or candies in the stores.
Each of the six transactions can be performed in any order, any number of times ( or more). The transactions cannot be split. For example, he cannot pay Au to buy balloons.
Find the maximum number of Au he can make.
Input
The first line contains a single integer (), the number of test cases.
Each of the next lines contains eight integers , , , , , , , (, ), separated by single spaces.
Output
For each test case, print one line containing the maximum number of Au.
Hint
In the first example, Prof. Pang buys balloons with Au and then sells balloons for Au. Then he buys candies with Au and sells candies for Au.