#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a c, a < c < b Int res=0; while(a>=c) a--,b--,res+=x; while(c>=b) a--,c--,res+=z; assert(a < c && c < b); if(min({a,b,c})<=0) return INF; return res; } Int p1(Int a,Int b,Int c,Int x,Int y,Int z){ // a < b > c return min(p1_1(a,b,c,x,y,z),p1_1(c,b,a,y,x,z)); } Int p2_1(Int a,Int b,Int c,Int x,Int y,Int z){ // a > b < c, b < a < c Int res=0; while(b>=a) b--,c--,res+=y; while(a>=c) a--,b--,res+=x; assert(b < a && a < c); if(min({a,b,c})<=0) return INF; return res; } Int p2(Int a,Int b,Int c,Int x,Int y,Int z){ // a > b < c return min(p2_1(a,b,c,x,y,z),p2_1(c,b,a,y,x,z)); } signed solve(){ Int a,b,c,x,y,z; cin>>a>>b>>c>>x>>y>>z; Int ans=min(p1(a,b,c,x,y,z),p2(a,b,c,x,y,z)); if(ans==INF) ans=-1; cout<>T; while(T--) solve(); return 0; }