I,J,R,=input,int,range T,S,N,=J(I()),R(3),R(2) def U(): global a s,b,c=sum(x),1,0 for j in R(4):b,c=b*(x[j]>=0),c+x[j]*X[j] for j in S:b*=s-x[j]<=B[(j+2)%3] if b:a=max(a,c) def V(): for k in S:B[k]=A[k]if k!=j else y for i in S: x[i],s=0,B[(i+2)%3] for k in N:x[(i+1+k)%3]=s-B[(i+k)%3] x[3]=s-x[(i+1)%3]-x[(i+2)%3] U() for w in N: x[3],x[0]=w,(B[0]+B[1]-B[2]-w)//2 for k in N:x[1+k]=B[1-k]-x[0]-w U() for t in R(T): A,B,X,x,a=list(map(J,I().split())),[0]*3,list(map(J,I().split())),[0]*4,0 for j in S: for y in R(A[j]+1):V() print(a)