Prof. Pang Earning Aus

시간 제한3초메모리 제한1024 MB

요약
Au, 풍선, 사탕 사이의 여섯 가지 고정 비율 거래와 한정된 재고가 주어질 때, 1 Au에서 얻을 수 있는 최대 Au를 구한다.
난이도

보통10점 중 7점

유형
수학, 그리디, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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 k_abk\_{ab} balloons for the price of 11 Au or buy k_cbk\_{cb} balloons for the price of 11 candy. In the candy store, Prof. Pang can buy k_ack\_{ac} candies for the price of 11 Au or buy k_bck\_{bc} candies for the price of 11 balloon. Prof. Pang can also sell one balloon and get k_bak\_{ba} Aus. He can sell one candy and get k_cak\_{ca} Aus. The only constraint to him is that there are only n_bn\_b balloons in the balloon store and only n_cn\_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 k_ab/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 (1≤T≤10001\le T\le 1000) denoting the number of test cases.

Each of the next TT lines contains eight integers n_bn\_b, n_cn\_c, k_abk\_{ab}, k_bak\_{ba}, k_ack\_{ac}, k_cak\_{ca}, k_bck\_{bc}, k_cbk\_{cb} (1≤n_b,n_c≤1091\le n\_b, n\_c\le 10^9, 1≤k_ab,k_ba,k_ac,k_ca,k_bc,k_cb≤1001\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.

힌트

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.

예제1

  1. 예제 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
    
    예상 출력
    7
    355
    239
    571
    637
    109