#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; bool isKado(ll x, ll y, ll z) { if (x == y || y == z || z == x)return false; if (x <= 0 || y <= 0 || z <= 0)return false; static ll a[3]; a[0] = x; a[1] = y; a[2] = z; sort(a, a + 3); return y != a[1]; } void solve() { int T; cin >> T; vi P{ 0,1,2 }; while (T--) { ll A[3], X[3], U[3]; rep(i, 3) { cin >> A[i]; } cin >> X[2] >> X[0] >> X[1]; ll ans = LLONG_MAX; do { rep(i, 3) { U[i] = A[i]; } ll cost = 0; // 二番目に高い=>一番高い for (int i = 1; i >= 0; --i) { ll maxi = LLONG_MIN; int p = P[i]; FOR(j, i + 1, 3) { int q = P[j]; smax(maxi, U[q]); } if (U[p] <= maxi) { ll cuts = maxi - U[p] + 1; rep(j, 3) { if (j != i) { int q = P[j]; U[q] -= cuts; } } cost += cuts * X[p]; } } if (isKado(U[0], U[1], U[2])) { smin(ans, cost); } } while (next_permutation(all(P))); cout << (ans == LLONG_MAX ? -1 : ans) << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }