q=int(input()) for _ in range(q): a,b,c,x,y,z=map(int,input().split()) ans=10**18 #a=tmp[2]: cost+=(tmp[0]-tmp[2]+1)*x tmp[0]=tmp[2]-1 if tmp[0]>0: ans=min(ans,cost) #c=tmp[1]: cost+=(tmp[0]-tmp[1]+1)*x tmp[0]=tmp[1]-1 if tmp[2]>=tmp[0]: cost+=(tmp[2]-tmp[0]+1)*z tmp[2]=tmp[0]-1 if tmp[2]>0: ans=min(ans,cost) #b=tmp[2]: cost+=(tmp[0]-tmp[2]+1)*x tmp[0]=tmp[2]-1 if tmp[1]>=tmp[0]: cost+=(tmp[1]-tmp[0]+1)*y tmp[1]=tmp[0]-1 if tmp[1]>0: ans=min(ans,cost) #b=tmp[0]: cost+=(tmp[2]-tmp[0]+1)*z tmp[2]=tmp[0]-1 if tmp[1]>=tmp[2]: cost+=(tmp[1]-tmp[2]+1)*y tmp[1]=tmp[2]-1 if tmp[1]>0: ans=min(ans,cost) if ans==10**18: print(-1) else: print(ans)