#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b x = {A,B,0, A,0,B-C,A}; vector y = {0,0,C,B-A,B, C,C}; rep(i,7){ ll xx = x[i], yy = y[i]; if(xx>=0 && yy>=0 && xx<=A && yy<=C && xx+yy<=B){ chmax(ans,X*xx+Y*yy); } } return ans; } ll f(vector ABC, vector XYZ){ ll ans = 0; rep(i,3){ chmax(ans,g(XYZ[i],XYZ[(i+1)%3],ABC[i],ABC[(i+2)%3],ABC[(i+1)%3])); } return ans; } void solve(){ ll A,B,C; cin >> A >> B >> C; ll X,Y,Z,W; cin >> X >> Y >> Z >> W; ll mx3 = min({A,B,C}); ll ans = 0; for(ll s3=0;s3<=mx3;s3++){ ll ws = max(W*s3,(X+Y+Z)*(s3/2)+W*(s3%2)); ll a = A-s3; ll b = B-s3; ll c = C-s3; chmax(ans,ws+f({a,b,c},{X,Y,Z})); } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--) solve(); return 0; }