#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int A[3], C[3]; ll del[3]; //--------------------------------------------------------------------------------------------------- void solve() { rep(i, 0, 3) cin >> A[i]; rep(i, 0, 3) cin >> C[i]; ll ans = infl; vector ord; rep(i, 0, 3) ord.push_back(i); do { if (ord[1] == 1) continue; rep(i, 0, 3) del[i] = 0; int pre = A[ord[0]]; ll tot = 0; rep(i, 1, 3) { int nxt = max(A[ord[i]], pre + 1); int d = nxt - A[ord[i]]; tot += 1LL * d * C[ord[i]]; pre = nxt; if (ord[i] == 0) { del[0] += d; del[1] += d; } else if (ord[i] == 1) { del[1] += d; del[2] += d; } else { del[0] += d; del[2] += d; } } if (del[0] < A[0] and del[1] < A[1] and del[2] < A[2]) chmin(ans, tot); } while (next_permutation(all(ord))); if (ans == infl) ans = -1; printf("%lld\n", ans); } //--------------------------------------------------------------------------------------------------- void _main() { int T; cin >> T; rep(t, 0, T) solve(); }