#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,a) for(int i=(int)0;i<(int)a;++i) #define pb push_back #define eb emplace_back using ll=long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; template string to_string(pair p); template string to_string(tuple p); template string to_string(tuple p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template string to_string(bitset v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast('0' + v[i]); } return res; } template string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template string to_string(pair p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template string to_string(tuple p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template string to_string(tuple p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << "\n"; } template void debug_out(Head H, Tail... T) { cerr << " " <>t; while(t--){ ll a,b,c,x,y,z; cin>>a>>b>>c>>x>>y>>z; ll ans=INF,cost=0; ll mid=a+b+c-max({a,b,c})-min({a,b,c}); if(a==c){ if(x>=y){ c--; cost+=z; } else { a--; cost+=x; } if(a<=0||c<=0) { cout<<-1<<"\n"; continue; } } if(c>a){ swap(a,c); swap(x,z); } if(b==a||c==b){ if(b==a){ a--; cost+=x; if(a==c){ if(x>=z){ c--; cost+=z; } else { c--; cost+=x; } } } else if(c==b){ if(y>=z){ c--; cost+=z; } else{ c--; cost+=y; } } if(c>0)ans=cost; } else { if(b!=mid)ans=cost; else { ll aa=a,cc=c; aa-=a-b+1; cost+=x*(a-b+1); if(aa==cc){ if(x>=z){ cc--; cost+=z; } else { cc--; cost+=x; } } if(cc>0)ans=cost; ll bb=b; bb-=b-c+1; if(bb>0)ans=min(ans,y*(b-c+1)); } } if(ans==INF)cout<<-1<<"\n"; else cout<