from collections import deque T=int(input()) for _ in range(T): A,B,C=map(int,input().split()) x,y,z,w=map(int,input().split()) d=dict() q=deque([(0,0,0,0)]) ans=0 while q: a,b,c,V=q.popleft() for da,db,dc,v in [[1,1,0,x],[0,1,1,y],[1,0,1,z],[1,1,1,w]]: if a+da<=A and b+db<=B and c+dc<=C: if (a+da,b+db,c+dc) not in d: d[(a+da,b+db,c+dc)]=V+v q.append((a+da,b+db,c+dc,V+v)) ans=max(ans,V+v) else: if d[(a+da,b+db,c+dc)]