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個を足すのに等しいが、構築可能判定が必要 if (C > 1 && B > 2) { // 1. A (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C)); } if (A > 1 && B > 2) { // 2. C (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C)); } if (A > 1 && C > 2) { // 3. B (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C)); } if (C > 1 && A > 2) { // 4. B (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C)); } if (cost == INF) System.out.println(-1); else System.out.println(cost); } } } }