#pragma GCC optimize("Ofast") #include using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define pii pair #define pll pair const double PI = acos(-1); const ll MOD = 1000000007; // const ll MOD = 998244353; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } /////////////////////////////////////////////////////////////// ll X,Y,Z; ll f1(ll A, ll B, ll C) { ll res = 0; if (A>= B) { res += (A-B+1LL)*X; A = B-1LL; } if (C >= A) { res += (C-A+1)*Z; C = A-1LL; } if (A <= 0 || C <= 0) return 5e18; return res; } ll f2(ll A, ll B, ll C) { ll res = 0; if (C >= B) { res += (C-B+1LL)*Z; C = B-1LL; } if (A >= C) { res += (A-C+1LL)*X; A = C-1LL; } if (A <= 0 || C <= 0) return 5e18; return res; } ll f3(ll A, ll B, ll C) { ll res = 0; if (A >= C) { res += (A-C+1LL)*X; A = C-1LL; } if (B >= A) { res += (B-A+1LL)*Y; B = A-1LL; } if (B <= 0 || A <= 0) return 5e18; return res; } ll f4(ll A, ll B, ll C) { ll res = 0; if (C >= A) { res += (C-A+1LL)*Z; C = A-1LL; } if (B >= C) { res += (B-C+1LL)*Y; B = C-1LL; } if (B <= 0 || C <= 0) return 5e18; return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { ll A,B,C; cin >> A >> B >> C >> X >> Y >> Z; ll ans = 5e18; chmin(ans,f1(A,B,C)); chmin(ans,f2(A,B,C)); chmin(ans,f3(A,B,C)); chmin(ans,f4(A,B,C)); if (ans == 5e18) cout << -1 << endl; else cout << ans << endl; } }