import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { String[] sa = br.readLine().split(" "); long a = Integer.parseInt(sa[0]); long b = Integer.parseInt(sa[1]); long c = Integer.parseInt(sa[2]); long x = Integer.parseInt(sa[3]); long y = Integer.parseInt(sa[4]); long z = Integer.parseInt(sa[5]); long ans = Long.MAX_VALUE; long[] v = new long[3]; v[0] = b; v[1] = a; v[2] = c; long c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0); long c2 = Math.max(v[2] + 1 - v[1], 0); if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) { long val = c1 * z + c2 * y; ans = Math.min(ans, val); } v[0] = b; v[1] = c; v[2] = a; c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0); c2 = Math.max(v[2] + 1 - v[1], 0); if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) { long val = c1 * z + c2 * x; ans = Math.min(ans, val); } v[0] = a; v[1] = c; v[2] = b; c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0); c2 = Math.max(v[2] + 1 - v[1], 0); if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) { long val = c1 * y + c2 * x; ans = Math.min(ans, val); } v[0] = c; v[1] = a; v[2] = b; c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0); c2 = Math.max(v[2] + 1 - v[1], 0); if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) { long val = c1 * x + c2 * y; ans = Math.min(ans, val); } if (ans == Long.MAX_VALUE) { System.out.println(-1); } else { System.out.println(ans); } } br.close(); } }