import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # 1つに +1 すると考えてあげればよい。作ってみてマイナスになってたらダメ T = int(readline()) m = map(int,read().split()) ABCXYZ = zip(m,m,m,m,m,m) INF = 10 ** 30 def type_231(A,B,C,X,Y,Z): a = C + 1 if a <= A: a = A b = a + 1 if b <= B: b = B x = a - A # 0,-1,-1 y = b - B # -1,0,-1 if any((A - y <= 0, B - x <= 0, C - x - y <= 0)): return INF return x * X + y * Y def type_213(A,B,C,X,Y,Z): a = B + 1 if a <= A: a = A c = a + 1 if c <= C: c = C x = a - A # 0,-1,-1 z = c - C # -1,-1,0 if any((A - z <= 0, B - x - z <= 0, C - x <= 0)): return INF return x * X + z * Z def solve(A,B,C,X,Y,Z): X,Y,Z = Y,Z,X x = min( type_231(A,B,C,X,Y,Z), type_231(C,B,A,Z,Y,X), type_213(A,B,C,X,Y,Z), type_213(C,B,A,Z,Y,X)) return x if x < INF else -1 answer = [solve(*args) for args in ABCXYZ] print('\n'.join(map(str,answer)))