public static void main(String[] args) throws IOException {

        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = new StringTokenizer("");
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));

        int T = nextInt();
        for (int t = 0; t < T; t++) {
            long B = nextInt();
            long W = nextInt();
            long X = nextInt();
            long Y = nextInt();
            long Z = nextInt();

            long a =  X * B + Y * W;
            long b =  X * B + (X + Z) * W;
            long c = (Y + Z) * B + Y * W;
            long d = (Y + Z) * B + (X + Z) * W;
            long min;
            if (a < b) {
                if (c < d) {
                    if (a < c) {
                        min = a;
                    } else {
                        min = c;
                    }
                } else {
                    if (a < d) {
                        min = a;
                    } else {
                        min = d;
                    }
                }
            } else {
                if (c < d) {
                    if (b < c) {
                        min = b;
                    } else {
                        min = c;
                    }
                } else {
                    if (b < d) {
                        min = b;
                    } else {
                        min = d;
                    }
                }
            }
            pw.println(min);
        }


        reader.close();
        pw.close();

    }