def calc(a,b,c,x,y,z): ret = 0 ba = a bb = b bc = c if max(x,y,z) == x: for i in range(min(a,b)+1): count = i*x a,b,c = ba,bb,bc if z >= y: count += z * min(a-i,c) c -= min(a-i,c) count += y * min(b-i,c) else: count += y * min(b-i,c) c -= min(b-i,c) count += z * min(a-i,c) ret = max(ret,count) elif max(x,y,z) == y: for i in range(min(b,c)+1): count = i*y a,b,c = ba,bb,bc if z >= x: count += z * min(c-i,a) a -= min(c-i,a) count += x * min(b-i,a) else: count += x * min(b-i,a) a -= min(b-i,a) count += z * min(c-i,a) ret = max(ret,count) else: for i in range(min(a,c)+1): count = i*z a,b,c = ba,bb,bc if y >= x: count += y * min(c-i,b) b -= min(c-i,b) count += x * min(a-i,b) else: count += x * min(a-i,b) b -= min(a-i,b) count += y * min(c-i,b) ret = max(ret,count) return ret def calc2(a,b,c,x,y,z,w): count = 0 ## abc for x in range(min(a,b,c)+1): ## ab for i in range(min(a-x,b-x)+1): ## ac for j in range(c-x+1): if i+j+x > a: break num = i * x + j * z + x*w num += min(b-i,c-j)*y count = max(count,num) return count def solve(): a,b,c = map(int,input().split()) x,y,z,w = map(int,input().split()) ans = 0 if max(x,y,z) >= w: ans = max(ans,calc(a,b,c,x,y,z)) elif x+y+z >= 2*w: ans = max(ans,calc(a,b,c,x,y,z)) if a*b*c: ans = max(ans,calc(a-1,b-1,c-1,x,y,z) + w) else: mi = min(a,b,c) base = 0 if mi > 5: base += (mi-5)*w a -= mi-5 b -= mi-5 c -= mi-5 base += calc2(a,b,c,x,y,z,w) ans = max(ans,base) print(ans) t = int(input()) for _ in range(t): solve()