def m(): I,R=input,range S,N,B,x=R(3),R(2),[0]*6,[0]*4 def J(): return list(map(int,I().split())) def U(): 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] return c if b else 0 def V(): m=0 for k in R(6):B[k]=A[k%3]if k%3!=j else y for i in S: for k in S:x[k]=B[i+2]-B[k+2] x[3]=B[i]+B[i+1]-B[i+2] m=max(m,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 m=max(m,U()) return m for t in R(int(I())): A,X,a=J(),J(),0 for j in S: for y in R(A[j]+1):a=max(a,V()) print(a) if __name__=="__main__":m()