import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { long t = System.currentTimeMillis(); new Main().run(); System.err.println(System.currentTimeMillis() - t); } long solve(long A,long B,long C,long X,long Y,long Z) { final long INF=Long.MAX_VALUE/3; long ret=INF,base=0; if(A==C) { --A; base+=X; if(A==0)return -1; } // A < C // B is min { if(A-1>0)ret=Math.min(ret,base+Y*Math.max(0,(B-(A-1)))); } // A < C // B is max { long cost=Math.max(0, A-(B-1))*X+Math.max(0, C-(B-1))*Z; A=Math.min(A, B-1); C=Math.min(C, B-1); if(A==C) { --A; cost+=X; } if(A>0)ret=Math.min(ret, cost+base); } return ret==INF?-1:ret; } void run() { Scanner sc = new Scanner(System.in); int T=sc.nextInt(); for(int t=0;tC||(A==C&&X>Z)) { A^=C;C^=A;A^=C;X^=Z;Z^=X;X^=Z; } System.out.println(solve(A,B,C,X,Y,Z)); } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }