#line 2 "/home/cocojapanpan/Procon_CPP/proconLibrary/lib/template/procon.hpp" #ifndef DEBUG // 提出時にassertはオフ #ifndef NDEBUG #define NDEBUG #endif // 定数倍高速化 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include using namespace std; using ll = long long; #define ALL(x) (x).begin(), (x).end() template using vec = vector; template inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } template constexpr T INF = 1'000'000'000; template <> constexpr int INF = 1'000'000'000; template <> constexpr ll INF = ll(INF) * INF * 2; #line 2 "main.cpp" ll solve() { ll A, B, C; cin >> A >> B >> C; ll X, Y, Z, W; cin >> X >> Y >> Z >> W; ll ans = 0; auto isValid = [&](ll x, ll y, ll z, ll w) { return 0 <= x && 0 <= y && 0 <= z && 0 <= w; }; auto calcEarn = [&](ll x, ll y, ll z, ll w) { if(!isValid(x, y, z, w)) return -1LL; return x * X + y * Y + z * Z + w * W; }; auto calc_x0 = [&](ll a, ll b, ll c) { ll x = 0; ll y = -a + c; ll z = -b + c; ll w = a + b - c; chmax(ans, calcEarn(x, y, z, w)); }; auto calc_y0 = [&](ll a, ll b, ll c) { ll x = a - c; ll y = 0; ll z = a - b; ll w = -a + b + c; chmax(ans, calcEarn(x, y, z, w)); }; auto calc_z0 = [&](ll a, ll b, ll c) { ll x = b - c; ll y = b - a; ll z = 0; ll w = a - b + c; chmax(ans, calcEarn(x, y, z, w)); }; auto calc_w0 = [&](ll a, ll b, ll c) { if((a + b + c) % 2) return; ll x = (a + b - c) / 2; ll y = (-a + b + c) / 2; ll z = (a - b + c) / 2; ll w = 0; chmax(ans, calcEarn(x, y, z, w)); }; auto calc_w1 = [&](ll a, ll b, ll c) { if((a + b + c - 1) % 2) return; ll x = (a + b - c - 1) / 2; ll y = (-a + b + c - 1) / 2; ll z = (a - b + c - 1) / 2; ll w = 1; chmax(ans, calcEarn(x, y, z, w)); }; vec> funList = { calc_x0, calc_y0, calc_z0, calc_w0, calc_w1 }; for(ll a = 0; a <= A; a++) { for(auto fun : funList) { fun(a, B, C); } } for(ll b = 0; b <= B; b++) { for(auto fun : funList) { fun(A, b, C); } } for(ll c = 0; c <= C; c++) { for(auto fun : funList) { fun(A, B, c); } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--) { cout << solve() << "\n"; } }