for _ in range(int(input())): a,b,c = map(int,input().split()) x,y,z,w = map(int,input().split()) ans = 0 for i in range(min(a,b)+1): ai = a-i; bi = b-i; ci = c l = min(ai,bi,ci); j = min(bi-l,ci-l); k = min(ai-l,ci-l) if y+z<=w: ans = max(ans,x*i+y*j+z*k+w*l) elif z<=y>=w: ans = max(ans,x*i+y*min(bi,ci)+z*min(ai,ci-min(bi,ci))) elif y<=z>=w: ans = max(ans,x*i+y*min(bi,ci-min(ai,ci))+z*min(ai,ci)) else: ci -= j+k+l; ans = max(ans,x*i+y*(j+ci)+z*(k+ci)+w*(l-ci)) print(ans)