import java.util.Scanner; public class Main { public static void main(String[] args) { new Main(); } public Main() { try (Scanner sc = new Scanner(System.in)) { int T = sc.nextInt(); while((T--) > 0) { int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(); long X = sc.nextInt(), Y = sc.nextInt(), Z = sc.nextInt(); int a, b, c; long INF = 2_000_000_000_000_000_000L; long cost = INF; // 2つを引くのは1個を足すのに等しいが、構築可能判定が必要 { // 1. A (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } { // 2. C (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } { // 3. B (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } { // 4. B (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } if (cost == INF) System.out.println(-1); else System.out.println(cost); } } } }