#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 (C >= A) { res += (C-A+1LL)*Y; B -= (C-A+1LL); C = A-1LL; } if (A >= B) { res += (A-B+1LL)*Z; C -= (A-B+1LL); A = B-1LL; } if (C <= 0) return 5e18; return res; } ll f2(ll A, ll B, ll C) { ll res = 0; if (A >= C) { res += (A-C+1LL)*X; B -= (A-C+1LL); A = C-1LL; } if (C >= B) { res += (C-B+1LL)*Z; A -= (C-B+1LL); C = B-1LL; } if (A <= 0) return 5e18; return res; } ll f3(ll A, ll B, ll C) { ll res = 0; if (B >= A) { res += (B-A+1LL)*Y; C -= (B-A+1LL); B = A-1LL; } if (A >= C) { res += (A-C+1LL)*X; B -= (A-C+1LL); A = C-1LL; } if (B <= 0) return 5e18; return res; } ll f4(ll A, ll B, ll C) { ll res = 0; if (B >= C) { res += (B-C+1LL)*X; A -= (B-C+1LL); B = C-1LL; } if (C >= A) { res += (C-A+1LL)*Y; B -= (C-A+1LL); C = A-1LL; } if (B <= 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; } }