#include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD = 1e9+7; //const ll MOD = 998244353; const ll INF = 1e18; using P = pair; template void chmin(T &a,T b){if(a>b)a=b;} template void chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } ostream &operator<<(ostream &os, pair&p){ return os << p.first << " " << p.second; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll t;cin>>t; while(t--){ vectora(3); vectorx(3); rep(i,0,3)cin>>a[i]; rep(i,0,3)cin>>x[i]; auto b=a; sort(ALL(b)); ll res=INF; ll mi=min({a[0]-1,a[1],a[2]-1}); if(mi>0){ ll c=(a[1]-mi)*x[1]; if(a[0]==a[2]){ if(mi==min(a[0],a[2])-1){ mi--; c+=x[1]; } ll mi2=min(a[0],a[2])-1; c+=min(x[0]*(a[0]-mi2),x[2]*(a[2]-mi2)); } if(mi>0)chmin(res,c); } if(a[1]>=3&&(a[2]>=2||a[0]>=2)){ ll x1=a[1]-1,x2=a[1]-2; if(a[0]>=x1&&a[2]>=x2) chmin(res,max(0LL,(a[0]-x1))*x[0]+max(0LL,(a[2]-x2))*x[2]); if(a[0]>=x2&&a[2]>=x1) chmin(res,max(0LL,(a[0]-x2))*x[0]+max(0LL,(a[2]-x1))*x[2]); if(a[0]