#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; kj += max(0ll, sum - c) * (x - w); kj += max(0ll, sum - a) * (y - w); kj += max(0ll, sum - b) * (z - w); ll mm = max({w, x, y, z}) - w; kj += mm * sum; ans = max(ans, kj); } cout << ans << endl; } int main () { int T; cin >> T; while (T --) { solve(); } }