SC1 - Starcraft I

no tags 

Background

You may play the game Starcraft I first before you do this problem ^_^.

Description

Suppose you are using Protoss. At the beginning of the game, you have n probes, a nexus and almost unlimited number of pylons. You can build a probe in the nexus per 3 Starcraft time units (STs), and this will cost you z units of minerals. A probe can gather x units of minerals or y units of gas per ST. What's the minimum time to get A units of minerals and B units of gas, if you build probes at nexus only and don't build any buildings?

Assume that in the current map there are almost unlimited mineral fields and unlimited vespene geysers, and on each vespene geyser, a Protoss Assimilator has been built successfully.

Input

Multiple test cases, the number of them is given in the very first line.

Each test case contains one line with 6 positive integers n, x, y, z, A, B separated by one space. All numbers in the input file will be less than 21.

Output

For each test case, output one line, which contains a single integer, the minimum time in ST.

Example

Input:
1
1 2 3 4 5 6

Output:
5

hide comments
kostya: 2010-07-11 08:37:26

yes

Josef Ziegler: 2010-07-10 19:38:21

For those who haven't played starcraft for a while: with " a probe in the nexus per 3 Starcraft time units(STs)" is meant "one at a time".


Added by:Fudan University Problem Setters
Date:2008-04-09
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO OBJC SQLITE
Resource:www.blizzard.com