import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int z = sc.nextInt(); sb.append(getCount(a, x, b, y, c, z)).append("\n"); } System.out.print(sb); } static long getCount(long a, long x, long b, long y, long c, long z) { long min = Long.MAX_VALUE; min = Math.min(min, getOrderCount(a, x, c, z, b, y)); min = Math.min(min, getOrderCount(c, z, a, x, b, y)); min = Math.min(min, getOrderCount(b, y, a, x, c, z)); min = Math.min(min, getOrderCount(b, y, c, z, a, x)); if (min == Long.MAX_VALUE) { return -1; } else { return min; } } static long getOrderCount(long a, long x, long b, long y, long c, long z) { long count = 0; if (a <= b) { count += (b - a + 1) * y; b = a - 1; } if (b <= c) { count += (c - b + 1) * z; c = b - 1; } if (c <= 0) { return Long.MAX_VALUE; } else { return count; } } }