T = int(input()) for i in range(T): a,b,c,x,y,z = map(int,input().split()) A = 10**9-a B = 10**9-b C = 10**9-c Z = x Y = z X = y ans = float("inf") #A>C>B na = A nc = min(A-1,C) nb = min(nc-1,B) if min(a - (B-nb+C-nc) , b - (A-na+C-nc) , c - (B-nb+A-na)) > 0: ans = min(ans, (A-na)*X + (B-nb)*Y + (C-nc)*Z) #B>C>A nb = B nc = min(B-1,C) na = min(nc-1,A) if min(a - (B-nb+C-nc) , b - (A-na+C-nc) , c - (B-nb+A-na)) > 0: ans = min(ans, (A-na)*X + (B-nb)*Y + (C-nc)*Z) t = A A = C C = t s = X X = Z Z = s #A>C>B na = A nc = min(A-1,C) nb = min(nc-1,B) if min(a - (B-nb+C-nc) , b - (A-na+C-nc) , c - (B-nb+A-na)) > 0: ans = min(ans, (A-na)*X + (B-nb)*Y + (C-nc)*Z) #B>C>A nb = B nc = min(B-1,C) na = min(nc-1,A) if min(a - (B-nb+C-nc) , b - (A-na+C-nc) , c - (B-nb+A-na)) > 0: ans = min(ans, (A-na)*X + (B-nb)*Y + (C-nc)*Z) if ans == float("inf"): print (-1) else: print (ans)