#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } int main() { constexpr int64_t inf = INT64_MAX / 4; auto kadomatsu = [](int a, int b, int c) { array, 4> ans; fill(begin(ans), end(ans), make_tuple(a, b, c)); { auto &[a, b, c] = ans[0]; if (b <= a) { a = b - 1; } if (a <= c) { c = a - 1; } } { auto &[a, b, c] = ans[1]; if (b <= c) { c = b - 1; } if (c <= a) { a = c - 1; } } { auto &[a, b, c] = ans[2]; if (c <= a) { a = c - 1; } if (a <= b) { b = a - 1; } } { auto &[a, b, c] = ans[3]; if (a <= c) { c = a - 1; } if (c <= b) { b = c - 1; } } return ans; }; int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int64_t x, y, z; cin >> x >> y >> z; int64_t ans = inf; for (auto [d, e, f] : kadomatsu(a, b, c)) { if (d <= 0 || e <= 0 || f <= 0) { continue; } ans = min(ans, x * abs(a - d) + y * (b - e) + z * (c - f)); } if (ans != inf) { cout << ans << endl; } else { cout << -1 << endl; } } }