INF = 1<<60 def two_same_kadomatsu(a,b,c,x,y,z): yield INF if b < c: if b > 2: yield min(x + z*(c - a + 1),2*x + z*(c - a)) if b > 1: yield y else: if c + 1 == b: if c > 1: yield min(2*x,x + z,2*y) else: yield x if c > 1: yield y*(b - c + 1) def completely_different_kadomatsu(a,b,c,x,y,z): yield INF if a + 1 == b: if a > 1: yield min(x + z*(c - a),z*(c - a + 1),y*(b - a + 1)) else: yield z*(c - b + 1) if a > 1: yield y*(b - a + 1) def main(): T = int(input()) for _ in range(T): a,b,c,x,y,z = map(int,input().split()) ans = INF if a == b == c: if a > 2: ans = min(ans,x + 2*z,2*x + z) elif a == b != c: ans = min(ans,min(two_same_kadomatsu(a,b,c,x,y,z))) elif a != b == c: ans = min(ans,min(two_same_kadomatsu(c,b,a,z,y,x))) elif c == a != b: if b > a: if a > 1: ans = min(ans,x,z) else: if b + 1 == a: if b > 1: ans = min(ans,y + min(x,z)) else: ans = min(ans,x,z) elif a < b < c: ans = min(ans,min(completely_different_kadomatsu(a,b,c,x,y,z))) elif c < b < a: ans = min(ans,min(completely_different_kadomatsu(c,b,a,z,y,x))) else: ans = 0 if ans == INF: print(-1) else: print(ans) if __name__ =='__main__': main()