def cost102(a, b, c, x, y, z): ret = 0 if c <= a: ret += (a-c+1)*x a = c-1 if a <= b: ret += (b - a + 1) * y b = a-1 if a<1 or b<1 or c<1: ret = 10**20 return ret def cost120(a, b, c, x, y, z): ret = 0 if b <= a: ret += (a-b+1)*x a = b-1 if a <= c: ret += (c - a + 1) * z c = a-1 if a<1 or b<1 or c<1: ret = 10**20 return ret t = int(input()) for _ in range(t): a,b,c,x,y,z = map(int,input().split()) cost = [] cost.append(cost120(a, b, c, x, y, z)) cost.append(cost120(c, b, a, z, y, x)) cost.append(cost102(a, b, c, x, y, z)) cost.append(cost102(c, b, a, z, y, x)) if min(cost) == 10**20: print(-1) else: print(min(cost))