#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a a, vector x, vector p){ ll res = 0; rep(j,2){ ll k = min(a[p[j]], a[(p[j]+1)%3]); res += k * x[p[j]]; a[p[j]] -= k; a[(p[j]+1)%3] -= k; } return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; vector p(3); rep(houren,t){ vector a(3), x(3); ll w; rep(i,3) cin >> a[i]; rep(i,3) cin >> x[i]; cin >> w; ll ans = 0; bool ok = true; for(ll i=0;ok;i++){ rep(j,3) p[j] = j; do{ chmax(ans, w*i+f(a,x,p)); }while(next_permutation(all(p))); rep(j,3){ a[j]--; if(a[j]<0) ok = false; } } cout << ans << '\n'; } return 0; }