#include<bits/stdc++.h>

using namespace std;

#define li long long

int main(){

li t;

cin >> t;

while(t–>0){

li n,e,h,a,b,c,temp,cakes=0,shakes=0,omletes=0;

cin >> n >> e >> h >> a >> b >> c;

li left = n,cost = 1e18;

temp = min(min(e,h),left); left -= temp; cakes = temp;

temp = min((h-cakes)/3,left); left -= temp;

temp = min((e-cakes)/2,left); left -= temp;

if(left > 0){

cout << -1 << “\n”;

continue;

}

shakes = min(h/3,n); cakes = 0;

while(shakes>=0){

if(a > c){

cakes = min(min(e,h-shakes*3),n-shakes);
omletes = min((e-cakes)/2,n-cakes-shakes);
}else{
omletes = min(e/2,n-shakes);
cakes = min(min(e-omletes*2,h-shakes

*3),n-omletes-shakes);*

}

if(cakes + omletes + shakes == n)

cost = min(aomletes+b

}

if(cakes + omletes + shakes == n)

cost = min(a

*shakes+c*cakes,cost);

shakes–;

}

cout << cost << “\n”;

}

}