#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; ll h2(int a, int b, int c, ll y, ll z){ int targ1 = min(b, c); int targ2 = min(a, c-targ1); ll ret = y * targ1 + z * targ2; targ2 = min(a, c); targ1 = min(b, c-targ2); ret = max(ret, y * targ1 + z * targ2); return ret; } void solve(){ int a, b, c; cin >> a >> b >> c; ll x, y, z, w; cin >> x >> y >> z >> w; ll ans = 0; for (int k=0; k<=min(a, min(b, c)); k++){ ll tmp = w * k; int ub = min(a, b) - k; int lb = 0; while (ub - lb > 2){ int t1 = (ub + 2 * lb) / 3; int t2 = (ub * 2 + lb) / 3; if (h2(a-k-t1, b-k-t1, c-k, y, z) + x * t1 < h2(a-k-t2, b-k-t2, c-k, y, z) + x * t2){ lb = t1; }else{ ub = t2; } } for (int t=lb; t<=ub; t++){ ans = max(ans, tmp + h2(a-k-t, b-k-t, c-k, y, z) + x * t); } } cout << ans << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--) solve(); }