#include using namespace std; using LL = long long int; #define incID(i, l, r) for(int i = (l) ; i < (r); ++i) #define incII(i, l, r) for(int i = (l) ; i <= (r); ++i) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i) #define decII(i, l, r) for(int i = (r) ; i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() auto setmin = [](auto & a, auto b) { return (b < a ? a = b, true : false); }; auto setmax = [](auto & a, auto b) { return (b > a ? a = b, true : false); }; auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); }; auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); }; auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); }; auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); }; auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; }; LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); } LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define SI(v) static_cast(v.size()) #define RF(e, v) for(auto & e: v) #define until(e) while(! (e)) #define if_not(e) if(! (e)) #define ef else if #define UR assert(false) // ---- ---- int main() { int t; cin >> t; auto f = [](LL a, LL b, LL c, LL x, LL y, LL z) -> LL { LL val = 0, cnt = 0, lim = min({ a, b, c }) - 1; if(a == c) { if_not(x <= z) { swap(x, z); } a++; cnt++; val += x; } if(cnt > lim) { return -1; } if(a < b && b > c) { return val; } if(a > b && b < c) { return val; } if_not(a > c) { swap(a, c); swap(x, z); } LL cnt_s = a + 1 - b; LL val_s = cnt_s * y; LL cnt_t = 0; LL val_t = 0; if(a < b + 1) { cnt_t += b + 1 - a; val_t += x * (b + 1 - a); a = b + 1; } if(c < b + 1) { cnt_t += b + 1 - c; val_t += z * (b + 1 - c); c = b + 1; } if(a == c) { cnt_t++; val_t += min(x, z); } LL INF = 4'000'000'000'000'000'000, ans = INF; if(cnt + cnt_s <= lim) { setmin(ans, val + val_s); } if(cnt + cnt_t <= lim) { setmin(ans, val + val_t); } if(ans == INF) { return -1; } return ans; }; inc(q, t) { LL a, b, c, x, y, z; cin >> a >> b >> c >> z >> x >> y; cout << f(a, b, c, x, y, z) << "\n"; } return 0; }