inf = 10 ** 20 def f(t1, t2, t3): val = 0 ma = t1[0] if t2[0] < ma: ma = t2[0] else: ma -= 1 val += t2[1] * (t2[0] - ma) if t3[0] < ma: ma = t3[0] else: ma -= 1 val += t3[1] * (t3[0] - ma) if ma <= 0: return inf else: return val T = int(input()) for _ in range(T): A, B, C, X, Y, Z = map(int, input().split()) ans = inf ta, tb, tc = (A, X), (B, Y), (C, Z) ans = min(ans, f(tb, ta, tc)) ans = min(ans, f(tb, tc, ta)) ans = min(ans, f(tc, ta, tb)) ans = min(ans, f(ta, tc, tb)) print(ans) if ans != inf else print(-1)