#include using namespace std; using ll = long long; void solve() { ll a, b, c, x, y, z, w; cin >> a >> b >> c >> x >> y >> z >> w; ll ans = 0; for (int sum = 0; sum <= (a + b + c) / 2; sum ++) { ll kj = sum * w; ll ssm = 0; kj += max(0ll, sum - c) * (x - w); kj += max(0ll, sum - a) * (y - w); kj += max(0ll, sum - b) * (z - w); ssm += max(0ll, sum - c); ssm += max(0ll, sum - a); ssm += max(0ll, sum - b); ll mm = max({w, x, y, z}) - w; kj += mm * (sum - ssm); if (sum < ssm) { continue; } ans = max(ans, kj); } cout << ans << endl; } int main () { int T; cin >> T; while (T --) { solve(); } }