#include using namespace std; long long solve(long long A,long long B,long long C,long long Y,long long Z) { long long tmp = 0; tmp += max(0LL,C-B+1)*Z; A -= max(0LL,C-B+1); C -= max(0LL,C-B+1); tmp += max(0LL,B-A+1)*Y; C -= max(0LL,B-A+1); B -= max(0LL,B-A+1); if(A <= 0 || B <= 0 || C <= 0) { return 1e18; } return tmp; } int main() { int T; cin >> T; while (T--) { long long A,B,C,X,Y,Z; cin >> A >> B >> C >> X >> Y >> Z; long long ans = 1e18; // 2 1 3 ans = min(ans,solve(B,A,C,Z,Y)); // 3 1 2 ans = min(ans,solve(B,C,A,Z,X)); // 2 3 1 ans = min(ans,solve(C,A,B,X,Y)); // 1 3 2 ans = min(ans,solve(A,C,B,Y,X)); if(ans == 1e18) { cout << -1 << endl; } else { cout << ans << endl; } } }