#include #include #include using namespace std; int T; main() { cin>>T; for(;T--;) { long A[3],C[3]; for(int i=0;i<3;i++)cin>>A[i]; for(int i=0;i<3;i++)cin>>C[i]; long ans=9e18; vectorid={0,1,2}; do{ if(id[1]==1)continue; long a=A[id[0]],b=A[id[1]],c=A[id[2]]; long now=0; if(b>=c) { now+=C[id[1]]*(b-c+1); b=c-1; } if(a>=b) { now+=C[id[0]]*(a-b+1); a=b-1; } if(a<=0)continue; ans=min(ans,now); }while(next_permutation(id.begin(),id.end())); if(ans>=6e18)ans=-1; cout<