// Main Code at the Bottom
import java.util.*;
import java.io.*;
public class Main{
	//Fast IO class
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    static long MOD=(long)1e9+7;
    //debug
    static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    // Pair
    static class pair{
    	long x,y;
    	pair(long a,long b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x,y);
        }
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);
    //Global variables and functions
    static int moves[][]= {{1,1},{0,1},{-1,0},{-1,-1},{0,-1},{1,0}};
    //Main function(The main code starts from here)
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
    	test=sc.nextInt();
    	while(test-->0) {
    		long x=sc.nextLong(),y=sc.nextLong();
    		long c[]=new long[7];
    		for(int i=1;i<7;i++) c[i]=sc.nextLong();
    		c[1]=Math.min(c[1], c[2]+c[6]);
    		c[4]=Math.min(c[4], c[3]+c[5]);
    		long ans=Long.MAX_VALUE,tmp=0;
    		if(x>0) {
    			if(y>=x) tmp=c[1]*x+c[2]*(y-x);
    			else tmp=c[1]*x+c[5]*Math.abs(y-x);
    			ans=Math.min(ans, tmp);
    			if(y>0) tmp=c[6]*x+c[2]*y;
    			else tmp=c[6]*x+c[5]*Math.abs(y);
    			ans=Math.min(ans, tmp);
    		}
    		else {
    			if(y>=x) tmp=c[4]*Math.abs(x)+c[2]*(y-x);
    			else tmp=c[4]*Math.abs(x)+c[5]*Math.abs(y-x);
    			ans=Math.min(ans, tmp);
    			if(y>0) tmp=-c[3]*x+c[2]*y;
    			else tmp=-c[3]*x+c[5]*Math.abs(y);
    			ans=Math.min(ans, tmp);
    		}
    		if(y>0) {
    			if(x>=y) tmp=c[1]*y+c[6]*(x-y);
    			else tmp=c[1]*y+c[3]*Math.abs(x-y);
    			ans=Math.min(ans, tmp);
    		}
    		else {
    			if(x>=y) tmp=c[4]*Math.abs(y)+c[6]*Math.abs(x-y);
    			else tmp=c[4]*Math.abs(y)+c[3]*Math.abs(x-y);
    			ans=Math.min(ans, tmp);
    		}
    		out.println(ans);
    	}
        out.flush();
        out.close();
    }
}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class FR4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
        t=scan.nextInt();
        while(t-->0){
            long x=scan.nextInt();
            long y=scan.nextInt();
            long[] c=new long[6];
            for(int i=0;i<6;i++){
                c[i]=scan.nextInt();
            }
            long ans=Long.MAX_VALUE;
            if(x>=0&&y>=0){
                long tx=x;
                long ty=y;
                long temp=0;
                temp=c[0]*Math.min(tx,ty);
                long min=Math.min(tx,ty);
                long max=Math.max(tx,ty);
                tx-=min;
                ty-=min;
                temp+=tx*c[5];
                temp+=ty*c[1];
                ans=Math.min(temp,ans);
                temp=0;
                tx=x;
                ty=y;
                ans=Math.min(tx*c[5]+ty*c[1],ans);
                temp+=max*c[0];
                tx=Math.abs(tx-max);
                ty=Math.abs(ty-max);
                temp+=tx*c[2];
                temp+=ty*c[4];
                ans=Math.min(ans,temp);
            }
            if(x<=0&&y<=0){
                long tx=Math.abs(x);
                long ty=Math.abs(y);
                long temp=0;
                temp=c[3]*Math.min(tx,ty);
                long min=Math.min(tx,ty);
                long max=Math.max(tx,ty);
                tx-=min;
                ty-=min;
                temp+=tx*c[2];
                temp+=ty*c[4];
                ans=Math.min(temp,ans);
                temp=0;
                tx=Math.abs(x);
                ty=Math.abs(y);
                ans=Math.min(tx*c[2]+ty*c[4],ans);
                temp+=max*c[3];
                tx=Math.abs(tx-max);
                ty=Math.abs(ty-max);
                temp+=tx*c[5];
                temp+=ty*c[1];
                ans=Math.min(ans,temp);
            }
            if(x>=0&&y<=0){
                long tx=x;
                long ty=Math.abs(y);
                long temp=0;
                temp=tx*c[0];
                ty+=tx;
                temp+=ty*c[4];
                ans=Math.min(ans,temp);
                tx=x;
                ty=Math.abs(y);
                temp=0;
                ans=Math.min(ans,tx*c[5]+ty*c[4]);
                temp+=ty*c[3];
                tx+=ty;
                temp+=c[5]*tx;
                ans=Math.min(ans,temp);
            }if(x<=0&&y>=0){
                long tx=Math.abs(x);
                long ty=y;
                long temp=0;
                temp=ty*c[0];
                tx+=ty;
                temp+=tx*c[2];
                ans=Math.min(ans,temp);
                tx=Math.abs(x);
                ty=y;
                temp=0;
                ans=Math.min(ans,tx*c[2]+ty*c[1]);
                temp+=tx*c[3];
                ty+=tx;
                temp+=c[1]*ty;
                ans=Math.min(ans,temp);
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


import java.io.*; import java.util.*;
public class CF1421D {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int T=Integer.parseInt(br.readLine());
        StringBuilder sb=new StringBuilder();

        for (int i = 0; i < T; i++) {
            StringTokenizer st=new StringTokenizer(br.readLine());
            int X=Integer.parseInt(st.nextToken());
            int Y=Integer.parseInt(st.nextToken());
            long[] c=new long[6];
            st=new StringTokenizer(br.readLine());
            for (int j = 0; j < 6; j++) {
                c[j]=Integer.parseInt(st.nextToken());
            }
            for (int j = 0; j < 6; j++) {
                for (int k = 0; k < 6; k++) {
                    if(c[k]+c[(k+2)%6]<c[(k+1)%6]){
                        c[(k+1)%6]=c[k]+c[(k+2)%6];
                    }
                }
            }
            //System.out.println(Arrays.toString(c));
            long ans=0;
            if(X>=0 && Y>=0){
                if(X<Y){
                    ans=(long) X*c[0]+(Y-X)*c[1];
                }else{
                    ans=(long) Y*c[0]+(X-Y)*c[5];
                }
            }else if(X<=0 && Y<=0){
                X=-X; Y=-Y;
                if(X<Y){
                    ans=(long) X*c[3]+(Y-X)*c[4];
                }else{
                    ans=(long) Y*c[3]+(X-Y)*c[2];
                }
            }else if(X<0 && Y>0){
                X=-X;
                ans=(long) X*c[2]+Y*c[1];
            }else{
                Y=-Y;
                ans=(long) X*c[5]+Y*c[4];
            }
            sb.append(ans).append("\n");

        }
        System.out.println(sb.toString());
    }

}
//Watch out for overflows (long), special cases!


import java.io.*; import java.util.*;
public class CF1421D {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int T=Integer.parseInt(br.readLine());
        StringBuilder sb=new StringBuilder();

        for (int i = 0; i < T; i++) {
            StringTokenizer st=new StringTokenizer(br.readLine());
            int X=Integer.parseInt(st.nextToken());
            int Y=Integer.parseInt(st.nextToken());
            long[] c=new long[6];
            st=new StringTokenizer(br.readLine());
            for (int j = 0; j < 6; j++) {
                c[j]=Integer.parseInt(st.nextToken());
            }
            for (int j = 0; j < 6; j++) {
                for (int k = 0; k < 6; k++) {
                    if(c[k]+c[(k+2)%6]<c[(k+1)%6]){
                        c[(k+1)%6]=c[k]+c[(k+2)%6];
                    }
                }
            }
            //System.out.println(Arrays.toString(c));
            long ans=0;
            if(X>=0 && Y>=0){
                if(X<Y){
                    ans=(long) X*c[0]+(Y-X)*c[5];
                }else{
                    ans=(long) Y*c[0]+(X-Y)*c[1];
                }
            }else if(X<=0 && Y<=0){
                X=-X; Y=-Y;
                if(X<Y){
                    ans=(long) X*c[3]+(Y-X)*c[4];
                }else{
                    ans=(long) Y*c[3]+(X-Y)*c[2];
                }
            }else if(X<0 && Y>0){
                X=-X;
                ans=(long) X*c[2]+Y*c[1];
            }else{
                Y=-Y;
                ans=(long) X*c[5]+Y*c[4];
            }
            sb.append(ans).append("\n");

        }
        System.out.println(sb.toString());
    }

}
//Watch out for overflows (long), special cases!


import java.io.*; import java.util.*;
public class CF1421D {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int T=Integer.parseInt(br.readLine());
        StringBuilder sb=new StringBuilder();

        for (int i = 0; i < T; i++) {
            StringTokenizer st=new StringTokenizer(br.readLine());
            int X=Integer.parseInt(st.nextToken());
            int Y=Integer.parseInt(st.nextToken());
            long[] c=new long[6];
            st=new StringTokenizer(br.readLine());
            for (int j = 0; j < 6; j++) {
                c[j]=Integer.parseInt(st.nextToken());
            }
            for (int j = 0; j < 6; j++) {
                for (int k = 0; k < 6; k++) {
                    if(c[k]+c[(k+2)%6]<c[(k+1)%6]){
                        c[(k+1)%6]=c[k]+c[(k+2)%6];
                    }
                }
            }
            //System.out.println(Arrays.toString(c));
            long ans=0;
            if(X>=0 && Y>=0){
                if(X<Y){
                    ans=(long) X*c[0]+(Y-X)*c[5];
                }else{
                    ans=(long) Y*c[0]+(X-Y)*c[1];
                }
            }else if(X<=0 && Y<=0){
                X=-X; Y=-Y;
                if(X<Y){
                    ans=(long) X*c[3]+(Y-X)*c[2];
                }else{
                    ans=(long) Y*c[3]+(X-Y)*c[4];
                }
            }else if(X<0 && Y>0){
                X=-X;
                ans=(long) X*c[2]+Y*c[1];
            }else{
                Y=-Y;
                ans=(long) X*c[5]+Y*c[4];
            }
            sb.append(ans).append("\n");

        }
        System.out.println(sb.toString());
    }

}
//Watch out for overflows (long), special cases!


import java.util.*;
import java.io.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = (int) 1e9 + 7;
	static long inf = (long) 1e16;
	static int n, m;
	static ArrayList<Integer>[] ad;
	static long[][] memo;
	static boolean f;
	static boolean vis[];
	static int[] px, Q[];
	static HashMap<Integer, Integer> hm;
	static String s;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int t = sc.nextInt();
		while (t-- > 0) {
			long ans = 0;
			int y = sc.nextInt();
			int x = sc.nextInt();
			int[] c = sc.nextArrInt(6);
			int[] dx = new int[] { 1, 1, 0, -1, -1, 0 };
			int[] dy = new int[] { 1, 0, -1, -1, 0, 1 };
			if (x == 0 && y != 0) {
				if (y > 0) {
					ans = c[5] * 1l * y;
					ans = Math.min(ans, y * 1l * c[0] + y * 1l * c[4]);
				} else {
					ans = c[2] * -1l * y;
					ans = Math.min(ans, y * -1l * c[3] + y * -1l * c[1]);
				}
			} else if (y == 0 && x != 0) {
				if (x > 0) {
					ans = c[1] * 1l * x;
					ans = Math.min(ans, x * 1l * c[0] + x * 1l * c[2]);
				} else {
					ans = c[4] * -1l * x;
					ans = Math.min(ans, x * -1l * c[3] + x * -1l * c[5]);
				}
			} else if (x != 0 && y != 0) {
//				int[] dx = new int[] { 1, 1, 0, -1, -1, 0 };
//				int[] dy = new int[] { 1, 0, -1, -1, 0, 1 };
				if (x > 0 && y > 0) {
					ans = x * 1l * c[1] + y * 1l * c[5];
					if (x > y) {
						ans = Math.min(ans, c[0] * 1l * y + (x - y) * 1l * c[1]);
						ans = Math.min(ans, c[0] * 1l * x + (x - y) * 1l * c[2]);
					} else {
						ans = Math.min(ans, c[0] * 1l * x + (y - x) * 1l * c[5]);
						ans = Math.min(ans, c[0] * 1l * y + (y - x) * 1l * c[4]);
					}
				} else if (x < 0 && y < 0) {
					x = -1 * x;
					y = y * -1;
					ans = x * 1l * c[4] + y * 1l * c[2];
					if (x > y) {
						ans = Math.min(ans, c[3] * 1l * y + (x - y) * 1l * c[4]);
						ans = Math.min(ans, c[3] * 1l * x + (x - y) * 1l * c[5]);
					} else {
						ans = Math.min(ans, c[3] * 1l * x + (y - x) * 1l * c[2]);
						ans = Math.min(ans, c[3] * 1l * y + (y - x) * 1l * c[1]);
					}
				} else {
//					int[] dx = new int[] { 1, 1, 0, -1, -1, 0 };
//					int[] dy = new int[] { 1, 0, -1, -1, 0, 1 };
					if (x > 0) {
						ans = x * 1l * c[1] + y * -1l * c[2];
					//	System.out.println(ans+" b");
						ans = Math.min(ans, c[0] * 1l * x + (x - y) * 1l * c[2]);
						ans = Math.min(ans, c[3] * -1l * y + (x - y) * 1l * c[1]);
					} else {
						ans = x * -1l * c[4] + y * 1l * c[5];
						ans = Math.min(ans, c[0] * 1l * y + (y - x) * 1l * c[4]);
						ans = Math.min(ans, c[3] * -1l * x + (y - x) * 1l * c[5]);
					}
				}
			}
			out.println(ans);
		}
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            String[] s=br.readLine().trim().split(" ");
            long X=Integer.parseInt(s[0]);
            long Y=Integer.parseInt(s[1]);

            long[] c=new long[6];
            s=br.readLine().trim().split(" ");
            for(i=0;i<6;i++) c[i]=Integer.parseInt(s[i]);

            for(i=0;i<6;i++)
            {
                long tmp = c[(i - 1 + 6) % 6] + c[(i + 1) % 6];
                if(c[i]> tmp) c[i]=tmp;
            }

            long cost=0;
            long[] used=new long[6];

            while (Math.abs(X)>0||Math.abs(Y)>0)
            {
                if(X==Y)
                {
                    if(X>0)
                    {
                        cost += c[0] * Math.abs(X);
                        used[0]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[3] * Math.abs(X);
                        used[3]+=Math.abs(X);
                    }

                    X=Y=0;
                }
                else if(Y!=0)
                {
                    if(Y>0)
                    {
                        cost += c[1] * Math.abs(Y);
                        used[1]+=Math.abs(Y);
                    }
                    else
                    {
                        cost += c[4] * Math.abs(Y);
                        used[4]+=Math.abs(Y);
                    }

                    Y=0;
                }
                else
                {
                    if(X>0)
                    {
                        cost += c[5] * Math.abs(X);
                        used[5]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[2] * Math.abs(X);
                        used[2]+=Math.abs(X);
                    }

                    X=0;
                }
            }

            for (i = 0; i < 6; i++)
            {
                if (c[(i + 1) % 6] < c[i] + c[(i + 2) % 6])
                {
                    long times = Math.min(used[i], used[(i + 2) % 6]);
                    used[i] -= times; cost-=times*c[i];
                    used[(i+2)%6]-=times; cost-=times*c[(i+2)%6];
                    used[(i+1)%6]+=times; cost+=times*c[(i+1)%6];
                }
            }

            sb.append(cost).append("\n");
        }
        System.out.println(sb);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            String[] s=br.readLine().trim().split(" ");
            long X=Integer.parseInt(s[0]);
            long Y=Integer.parseInt(s[1]);

            long[] c=new long[6];
            s=br.readLine().trim().split(" ");
            for(i=0;i<6;i++) c[i]=Integer.parseInt(s[i]);

            while (true)
            {
                boolean flag=false;
                for(i=0;i<6;i++)
                {
                    long tmp = c[(i - 1 + 6) % 6] + c[(i + 1) % 6];
                    if(c[i]> tmp)
                    {
                        c[i]= tmp;
                        flag=true;
                    }
                }
                if(!flag) break;
            }

            long cost=0;
            long[] used=new long[6];

            while (Math.abs(X)>0||Math.abs(Y)>0)
            {
                if(X==Y)
                {
                    if(X>0)
                    {
                        cost += c[0] * Math.abs(X);
                        used[0]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[3] * Math.abs(X);
                        used[3]+=Math.abs(X);
                    }

                    X=Y=0;
                }
                else if(Y!=0)
                {
                    if(Y>0)
                    {
                        cost += c[1] * Math.abs(Y);
                        used[1]+=Math.abs(Y);
                    }
                    else
                    {
                        cost += c[4] * Math.abs(Y);
                        used[4]+=Math.abs(Y);
                    }

                    Y=0;
                }
                else
                {
                    if(X>0)
                    {
                        cost += c[5] * Math.abs(X);
                        used[5]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[2] * Math.abs(X);
                        used[2]+=Math.abs(X);
                    }

                    X=0;
                }
            }

            for (i = 0; i < 6; i++)
            {
                if (c[(i + 1) % 6] < c[i] + c[(i + 2) % 6])
                {
                    long times = Math.min(used[i], used[(i + 2) % 6]);
                    used[i] -= times; cost-=times*c[i];
                    used[(i+2)%6]-=times; cost-=times*c[(i+2)%6];
                    used[(i+1)%6]+=times; cost+=times*c[(i+1)%6];
                }
            }

            sb.append(cost).append("\n");
        }
        System.out.println(sb);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            String[] s=br.readLine().trim().split(" ");
            long X=Integer.parseInt(s[0]);
            long Y=Integer.parseInt(s[1]);

            long[] c=new long[6];
            s=br.readLine().trim().split(" ");
            for(i=0;i<6;i++) c[i]=Integer.parseInt(s[i]);

            while (true)
            {
                boolean flag=false;
                for(i=0;i<6;i++)
                {
                    long tmp = c[(i - 1 + 6) % 6] + c[(i + 1) % 6];
                    if(c[i]> tmp)
                    {
                        c[i]= tmp;
                        flag=true;
                    }
                }
                if(!flag) break;
            }

            long cost=0;
            long[] used=new long[6];

            while (Math.abs(X)>0||Math.abs(Y)>0)
            {
                if(X==Y)
                {
                    if(X>0)
                    {
                        cost += c[0] * Math.abs(X);
                        used[0]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[3] * Math.abs(X);
                        used[3]+=Math.abs(X);
                    }

                    X=Y=0;
                }
                else if(Y!=0)
                {
                    if(Y>0)
                    {
                        cost += c[1] * Math.abs(Y);
                        used[1]+=Math.abs(Y);
                    }
                    else
                    {
                        cost += c[4] * Math.abs(Y);
                        used[4]+=Math.abs(Y);
                    }

                    Y=0;
                }
                else
                {
                    if(X>0)
                    {
                        cost += c[5] * Math.abs(X);
                        used[5]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[2] * Math.abs(X);
                        used[2]+=Math.abs(X);
                    }

                    X=0;
                }
            }

            int tmp=10;
            while (tmp-->0)
            {
                for (i = 0; i < 6; i++)
                {
                    if (c[(i + 1) % 6] < c[i] + c[(i + 2) % 6])
                    {
                        long times = Math.min(used[i], used[(i + 2) % 6]);
                        used[i] -= times; cost-=times*c[i];
                        used[(i+2)%6]-=times; cost-=times*c[(i+2)%6];
                        used[(i+1)%6]+=times; cost+=times*c[(i+1)%6];
                    }
                }
            }

            sb.append(cost).append("\n");
        }
        System.out.println(sb);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            String[] s=br.readLine().trim().split(" ");
            long X=Integer.parseInt(s[0]);
            long Y=Integer.parseInt(s[1]);

            long[] c=new long[6];
            s=br.readLine().trim().split(" ");
            for(i=0;i<6;i++) c[i]=Integer.parseInt(s[i]);

            while (true)
            {
                boolean flag=false;
                for(i=0;i<6;i++)
                {
                    long tmp = c[(i - 1 + 6) % 6] + c[(i + 1) % 6];
                    if(c[i]> tmp)
                    {
                        c[i]= tmp;
                        flag=true;
                    }
                }
                if(!flag) break;
            }

            long cost=0;
            long[] used=new long[6];

            while (Math.abs(X)>0||Math.abs(Y)>0)
            {
                if(X==Y)
                {
                    if(X>0)
                    {
                        cost += c[0] * Math.abs(X);
                        used[0]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[3] * Math.abs(X);
                        used[3]+=Math.abs(X);
                    }

                    X=Y=0;
                }
                else if(Y!=0)
                {
                    if(Y>0)
                    {
                        cost += c[1] * Math.abs(Y);
                        used[1]+=Math.abs(Y);
                    }
                    else
                    {
                        cost += c[4] * Math.abs(Y);
                        used[4]+=Math.abs(Y);
                    }

                    Y=0;
                }
                else
                {
                    if(X>0)
                    {
                        cost += c[5] * Math.abs(X);
                        used[5]+=Math.abs(X);
                    }
                    else
                    {
                        cost += c[2] * Math.abs(X);
                        used[2]+=Math.abs(X);
                    }

                    X=0;
                }
            }

            int tmp=2;
            while (tmp-->0)
            {
                for (i = 0; i < 6; i++)
                {
                    if (c[(i + 1) % 6] < c[i] + c[(i + 2) % 6])
                    {
                        long times = Math.min(used[i], used[(i + 2) % 6]);
                        used[i] -= times; cost-=times*c[i];
                        used[(i+2)%6]-=times; cost-=times*c[(i+2)%6];
                        used[(i+1)%6]+=times; cost+=times*c[(i+1)%6];
                    }
                }
            }

            sb.append(cost).append("\n");
        }
        System.out.println(sb);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            String[] s=br.readLine().trim().split(" ");
            long X=Integer.parseInt(s[0]);
            long Y=Integer.parseInt(s[1]);

            long[] c=new long[6];
            s=br.readLine().trim().split(" ");
            for(i=0;i<6;i++) c[i]=Integer.parseInt(s[i]);

            while (true)
            {
                boolean flag=false;
                for(i=0;i<6;i++)
                {
                    long tmp = c[(i - 1 + 6) % 6] + c[(i + 1) % 6];
                    if(c[i]> tmp)
                    {
                        c[i]= tmp;
                        flag=true;
                    }
                }
                if(!flag) break;
            }

            long cost=0;
            while (Math.abs(X)>0||Math.abs(Y)>0)
            {
                if(X==Y)
                {
                    if(X>0) cost+=c[0]*Math.abs(X);
                    else cost+=c[3]*Math.abs(X);

                    X=Y=0;
                }
                else if(Y!=0)
                {
                    if(Y>0) cost+=c[1]*Math.abs(Y);
                    else cost+=c[4]*Math.abs(Y);

                    Y=0;
                }
                else
                {
                    if(X>0) cost+=c[5]*Math.abs(X);
                    else cost += c[2] * Math.abs(X);

                    X=0;
                }
            }
            sb.append(cost).append("\n");
        }
        System.out.println(sb);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Solution{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        int[][] dest = new int[t][2];
        int[][] cost = new int[t][6];
        for(int i = 0; i<t; i++) {
        	dest[i][0] = scanner.nextInt();
        	dest[i][1] = scanner.nextInt();
        	for(int k = 0; k<6; k++) {
        		cost[i][k] = scanner.nextInt();
        	}
        }
        int[] dx = {1, 0, -1, -1, 0, 1};
        int[] dy = {1,1,0,-1,-1,0};

        for(int i = 0; i<t; i++) {
        	System.out.println(find(dest[i][0], dest[i][1], cost[i], dx, dy));
        }

    }

	private static long find(int x, int y, int [] c, int[] dx, int[] dy) {
		// TODO Auto-generated method stub
		long ans = 0;
		for (int i = 0; i < 6; ++i) {
            for (int j = i; j < 6; ++j) {
                int det = dx[i] * dy[j] - dx[j] * dy[i];
                //assert(abs(det) <= 1);
                if (det != 0) {
                    long t1 = x * dy[j] - y * dx[j];
                    long t2 = dx[i] * y - dy[i] * x;
                    t1 /= det;
                    t2 /= det;
                    if (t1 >= 0 && t2 >= 0) {
                        ans = Math.min(ans, Math.abs(t1) * c[i] + Math.abs(t2) * c[j]);
                    }
                }
        }
}
		return ans;

	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Solution{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        int[][] dest = new int[t][2];
        int[][] cost = new int[t][6];
        for(int i = 0; i<t; i++) {
        	dest[i][0] = scanner.nextInt();
        	dest[i][1] = scanner.nextInt();
        	for(int k = 0; k<6; k++) {
        		cost[i][k] = scanner.nextInt();
        	}
        }
        int[] dx = {1, 0, -1, -1, 0, 1};
        int[] dy = {1,1,0,-1,-1,0};

        for(int i = 0; i<t; i++) {
        	System.out.println(find(dest[i][0], dest[i][1], cost[i], dx, dy));
        }

    }

	private static long find(int x, int y, int [] c, int[] dx, int[] dy) {
		// TODO Auto-generated method stub
		long ans = Long.MAX_VALUE;
		for (int i = 0; i < 6; ++i) {
            for (int j = i; j < 6; ++j) {
                int det = dx[i] * dy[j] - dx[j] * dy[i];
                //assert(abs(det) <= 1);
                if (det != 0) {
                    long t1 = x * dy[j] - y * dx[j];
                    long t2 = dx[i] * y - dy[i] * x;
                    t1 /= det;
                    t2 /= det;
                    if (t1 >= 0 && t2 >= 0) {
                        ans = Math.min(ans, Math.abs(t1) * c[i] + Math.abs(t2) * c[j]);
                    }
                }
        }
}
		return ans;

	}

}


import java.util.*;
import java.io.*;
public class MainClass
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int t = in.nextInt();
        StringBuilder stringBuilder = new StringBuilder();
        while (t-- > 0)
        {
            long x = in.nextLong();
            long y = in.nextLong();
            long[] C = new long[6];
            for (int i=0;i<6;i++)
                C[i] = in.nextLong();
            long[] D = Arrays.copyOf(C, 6);
            for (int i=0;i<6;i++)
                D[i] = Math.min(D[i], C[(i + 5) % 6] + C[(i + 1) % 6]);
            long ans = 0L;
            if (x * y >= 0L)
            {
                long mm = Math.min(Math.abs(x), Math.abs(y));
                if (x > 0 || y > 0)
                {
                    ans += mm * D[0];
                    x -= mm;
                    y -= mm;
                }
                else
                {
                    ans += mm * D[3];
                    x += mm;
                    y += mm;
                }
                if (x == 0L)
                {
                    if (y > 0L)
                        ans += D[1] * y;
                    else
                        ans -= D[4] * y;
                }
                else
                {
                    if (x > 0L)
                        ans += D[5] * x;
                    else
                        ans -= D[2] * x;
                }
            }
            else
            {
                if (x < 0L)
                {
                    ans = D[2] * -x + D[1] * y;
                }
                else
                {
                    ans = D[5] * x + D[4] * -y;
                }
            }
            stringBuilder.append(ans).append("\n");
        }
        System.out.println(stringBuilder);
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


/**/
    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.lang.*;
    import java.math.*;
public class Main{
/*********************************************Constants***********************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static ArrayList<Integer> graph[];
    static int pptr=0,pptrmax=0;
    static String st[];
/*****************************************Solution Begins*********************************/
    static int dx[]={1,0,-1,-1,0,1};
    static int dy[]={1,1,0,-1,-1,0};
    static long cost[];
    static long x,y;
    static long ans;

    static void dfs(int j,long x,long y,long cs){
        if(cs>=ans)
            return;

            if(x==0 && y==0){
                ans=Math.min(ans,cs);
                return;
            }
        if(j==3){
            return;
        }
        for(int i=0;i<6;i++){
                long xx=Math.abs(x);
                long yy=Math.abs(y);
                if(xx!=0)
                dfs(j+1,x+ xx*dx[i],y+ xx*dy[i], cs+ xx*cost[i]);

                if(yy!=0)
                dfs(j+1,x+ yy*dx[i],y+ yy*dy[i],cs+ yy*cost[i]);

        }
    }
    public static void main(String args[]) throws Exception{
        int tt=pi();
        for(int i=0;i<6;i++){
            dy[i]=-dy[i];
            dx[i]=-dx[i];
        }
        while(tt-->0){
            x=pl();
            y=pl();
            cost=new long[6];
            for(int i=0;i<6;i++){
                cost[i]=pl();
            }
            ans=Long.MAX_VALUE;

            dfs(0,x,y,0);
            out.println(ans);

        }
/****************************************Solution Ends*************************************/
        clr();
    }
    static void clr(){
        out.flush();
        out.close();
    }
    static void nl() throws Exception{
        pptr=0;
        st=br.readLine().split(" ");
        pptrmax=st.length;
    }
    static void nls() throws Exception{
        pptr=0;
        st=br.readLine().split("");
        pptrmax=st.length;
    }
    static int pi() throws Exception{
        if(pptr==pptrmax)
            nl();
        return Integer.parseInt(st[pptr++]);
    }
    static long pl() throws Exception{
        if(pptr==pptrmax)
            nl();
        return Long.parseLong(st[pptr++]);
    }
    static double pd() throws Exception{
        if(pptr==pptrmax)
            nl();
        return Double.parseDouble(st[pptr++]);
    }
    static String ps() throws Exception{
        if(pptr==pptrmax)
            nl();
        return st[pptr++];
    }
/***************************************Precision Printing*********************************/
        static void printPrecision(double d){
            DecimalFormat ft = new DecimalFormat("0.00000000000");
            out.println(ft.format(d));
        }
/**************************************Bit Count************************************/
    static int countBit(long mask){
        int ans=0;
        while(mask!=0){
            mask&=(mask-1);
            ans++;
        }
        return ans;
    }
/******************************************Graph******************************************/
    static void Makegraph(int n){
        graph=new ArrayList[n];
        for(int i=0;i<n;i++)
            graph[i]=new ArrayList<>();
    }
    static void addEdge(int a,int b){
        graph[a].add(b);
    }
    // static void addEdge(int a,int b,int c){
    //     graph[a].add(new Pair(b,c));
    // }
/******************************************Pair*****************************************/
    static class Pair{
        int u;
        int v;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/*****************************************DEBUG********************************************/
    public static void debug(Object... o){
        System.err.println(Arrays.deepToString(o));
    }
/************************************Modular Exponentiation********************************/
    static long modulo(long a,long b,long c){
        long x=1,y=a%c;
        while(b > 0){
            if(b%2 == 1)
                x=(x*y)%c;
            y = (y*y)%c;
            b = b>>1;
        }
        return  x%c;
    }
/********************************************GCD*******************************************/
    static long gcd(long x, long y){
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y;
        b = (x < y) ? x : y;
        r = b;
        while(a % b != 0){
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = {1, 0, -1, -1, 0, 1};
            int[] dc = {1, 1, 0, -1, -1, 0};
            int[] C = new int[6];
            for (int i = 0; i < 6; i++) C[i] = in.nextInt();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    int signRow = Integer.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (Long.compare(col - y, 0) != dc[j]) continue;
                    long goJ = Math.abs(col - y);
                    if (goJ * dr[j] + row != row) continue;
                    ans = Math.min(ans, goI * C[i] + Math.abs(col - y) * C[j]);
                }
            }

            //right
            int r = row - col, c = 0;
            int x = r * C[2] + (row - r) * C[0];
            if (x > 0) ans = Math.min(ans, x);

            //left
            r = c = col;
            x = Math.abs(r) * C[3] + (row - r) * C[5];
            if (x > 0) ans = Math.min(ans, x);

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = {1, 0, -1, -1, 0, 1};
            int[] dc = {1, 1, 0, -1, -1, 0};
            long[] C = new long[6];
            for (int i = 0; i < 6; i++) C[i] = in.nextLong();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    int signRow = Integer.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (Long.compare(col - y, 0) != dc[j]) continue;
                    long goJ = Math.abs(col - y);
                    if (goJ * dr[j] + row != row) continue;
                    ans = Math.min(ans, goI * C[i] + Math.abs(col - y) * C[j]);
                }
            }

            //right
            int r = row - col, c = 0;
            long x = r * C[2] + (row - r) * C[0];
            if (x > 0) ans = Math.min(ans, x);

            //left
            r = c = col;
            x = Math.abs(r) * C[3] + (row - r) * C[5];
            if (x > 0) ans = Math.min(ans, x);

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = new int[]{1, 0, -1, -1, 0, 1};
            int[] dc = new int[]{1, 1, 0, -1, -1, 0};
            int[] c = new int[6];
            for (int i = 0; i < 6; i++) c[i] = in.nextInt();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    int signRow = Long.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (y == col) {
                        ans = Math.min(ans, goI * c[i]);
                        continue;
                    }

                    if (Long.compare(col - y, 0) != dc[j] || dr[j] != 0) continue;

//                out.println((i+1)+" "+(j+1));

                    ans = Math.min(ans, goI * c[i] + Math.abs(col - y) * c[j]);
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = {1, 0, -1, -1, 0, 1};
            int[] dc = {1, 1, 0, -1, -1, 0};
            int[] C = new int[6];
            for (int i = 0; i < 6; i++) C[i] = in.nextInt();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    int signRow = Integer.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (Long.compare(col - y, 0) != dc[j]) continue;
                    long goJ = Math.abs(col - y);
                    if (goJ * dr[j] + row != row) continue;
                    ans = Math.min(ans, goI * C[i] + Math.abs(col - y) * C[j]);
                }
            }

            //right
            int r = row - col, c = 0;
            int x = r * C[2] + (row - r) * C[2];
            if (x > 0) ans = Math.min(ans, x);

            //left
            r = c = col;
            x = Math.abs(r) * C[2] + (row - r) * C[2];
            if (x > 0) ans = Math.min(ans, x);

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        long[] C = new long[7];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            for (int i = 1; i <= 6; i++) C[i] = in.nextInt();

            out.println(Math.min(Math.min(c1(x) + c2(y), c3(x) + c2(y - x)), c1(x - y) + c3(y)));
        }

        long c1(int x) {
            return x > 0 ? C[6] * x : C[3] * -x;
        }

        long c2(int y) {
            return y > 0 ? C[2] * y : C[5] * -y;
        }

        long c3(int x) {
            return x > 0 ? C[1] * x : C[4] * -x;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = new int[]{1, 0, -1, -1, 0, 1};
            int[] dc = new int[]{1, 1, 0, -1, -1, 0};
            int[] c = new int[6];
            for (int i = 0; i < 6; i++) c[i] = in.nextInt();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    if (i == j) continue;
                    int signRow = Long.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (y == col) {
                        ans = Math.min(ans, goI * c[i]);
                        continue;
                    }

                    if (Long.compare(col - y, 0) != dc[j] || dr[j] != 0) continue;

//                out.println((i+1)+" "+(j+1));

                    ans = Math.min(ans, goI * c[i] + Math.abs(col - y) * c[j]);
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = {1, 0, -1, -1, 0, 1};
            int[] dc = {1, 1, 0, -1, -1, 0};
            int[] c = new int[6];
            for (int i = 0; i < 6; i++) c[i] = in.nextInt();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    int signRow = Integer.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (y == col) {
                        ans = Math.min(ans, goI * c[i]);
                        continue;
                    }

                    if (Long.compare(col - y, 0) != dc[j]) continue;
                    long goJ = Math.abs(col - y);
                    if (goJ * dr[j] + row != row) continue;

                    ans = Math.min(ans, goI * c[i] + Math.abs(col - y) * c[j]);
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ch
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int row = in.nextInt(), col = in.nextInt();
            int[] dr = {1, 0, -1, -1, 0, 1};
            int[] dc = {1, 1, 0, -1, -1, 0};
            long[] C = new long[6];
            for (int i = 0; i < 6; i++) C[i] = in.nextLong();

            long ans = Long.MAX_VALUE;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    int signRow = Integer.compare(row, 0);
                    if (signRow != dr[i]) continue;
                    long goI = Math.abs(row);
                    long y = goI * dc[i];
                    if (Long.compare(col - y, 0) != dc[j]) continue;
                    long goJ = Math.abs(col - y);
                    if (goJ * dr[j] + row != row) continue;
                    ans = Math.min(ans, goI * C[i] + Math.abs(col - y) * C[j]);
                }
            }

            //right
            if (col > 0) {
                int r = row - col, c = 0;
                long x = Math.abs(r) * C[2] + Math.abs(row - r) * C[0];
                ans = Math.min(ans, x);
            }

            //left
            if (col < 0) {
                int r, c;
                r = c = col;
                long x = Math.abs(r) * C[3] + Math.abs(row - r) * C[5];
                ans = Math.min(ans, x);
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;

public class Coding {

    private static BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
    private static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
    static int[] segmentTree = new int[4*100000 + 11];

    public static void main(String[] args) {
        try {
            run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void run() throws Exception {
        InputModule inp = new InputModule();
        OutputModule out = new OutputModule();
        int t = inp.cinInt();
        while (t > 0) {
            long[] inps = inp.cinLongArray(2);
            long x = inps[0];
            long y = inps[1];
            inps = inp.cinLongArray(6);
            long c1 = inps[0];
            long c2 = inps[1];
            long c3 = inps[2];
            long c4 = inps[3];
            long c5 = inps[4];
            long c6 = inps[5];
            long ans = Long.MAX_VALUE;
            if (x>=0 && y>=0) {
                ans = c6*x + c2*y;
                if (x<y) {
                    ans = Math.min(ans, c1*x + (y-x)*c2);
                    ans = Math.min(ans, c1*y + (y-x)*c3);
                } else {
                    ans = Math.min(ans, c1*y + (x-y)*c6);
                    ans = Math.min(ans, c1*x + (x-y)*c5);
                }
            } else if (x<=0 && y<=0) {
                x = Math.abs(x);
                y = Math.abs(y);
                ans = c3*x + c5*y;
                if (x<y) {
                    ans = Math.min(ans, c4*x + (y-x)*c5);
                    ans = Math.min(ans, c4*y + (y-x)*c6);
                } else {
                    ans = Math.min(ans, c4*y + (x-y)*c3);
                    ans = Math.min(ans, c4*x + (x-y)*c2);
                }
            } else if (x>0 && y<0) {
                y = Math.abs(y);
                ans = c6*x + c5*y;
                ans = Math.min(ans, c4*y + (x+y)*c6);
                ans = Math.min(ans, c1*x + (x+y)*c5);
            } else if (x<0 && y>0) {
                x = Math.abs(x);
                ans = c3*x + c2*y;
                ans = Math.min(ans, c4*x + (x+y)*c2);
                ans = Math.min(ans, c1*y + (x+y)*c3);
            }
            out.printLong(ans);
            t--;
        }
    }

    private static class InputModule {
        private int cinInt() throws Exception {
            return Integer.parseInt(bi.readLine().split(" ")[0].trim());
        }

        private long cinLong() throws Exception {
            return Long.parseLong(bi.readLine().split(" ")[0].trim());
        }

        private Double cinDouble() throws Exception {
            return Double.parseDouble(bi.readLine().split(" ")[0].trim());
        }

        private int[] cinIntArray(int n) throws Exception {
            String input = bi.readLine();
            String[] values = input.split(" ");
            int[] ar = new int[n];
            for (int i = 0; i < n; ++i) {
                ar[i] = Integer.parseInt(values[i]);
            }
            return ar;
        }

        private long[] cinLongArray(int n) throws Exception {
            String input = bi.readLine();
            String[] values = input.split(" ");
            long[] ar = new long[n];
            for (int i = 0; i < n; ++i) {
                ar[i] = Long.parseLong(values[i]);
            }
            return ar;
        }
    }

    private static class OutputModule {
        private void printInt(int ans) throws Exception {
            writer.append(ans + "\n");
            writer.flush();
        }

        private void printLong(long ans) throws Exception {
            writer.append(ans + "\n");
            writer.flush();
        }

        private void printDouble(Double ans) throws Exception {
            writer.append(String.format("%.10f", ans));
            writer.append("\n");
            writer.flush();
        }

        private void printIntArray(int[] ans) throws Exception {
            for (int i = 0; i < ans.length; ++i) {
                writer.append(ans[i] + " ");
            }
            writer.append("\n");
            writer.flush();
        }

        private void printLongArray(long[] ans) throws Exception {
            for (int i = 0; i < ans.length; ++i) {
                writer.append(ans[i] + " ");
            }
            writer.append("\n");
            writer.flush();
        }
    }
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
Shining through the city with a little funk and soul
*/
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         while(T-->0)
         {
            st = new StringTokenizer(infile.readLine());
            long X = Long.parseLong(st.nextToken());
            long Y = Long.parseLong(st.nextToken());
            st = new StringTokenizer(infile.readLine());
            long[] arr = new long[6];
            for(int i=0; i < 6; i++)
               arr[i] = Long.parseLong(st.nextToken());
            int turns = 15;
            int head = 0;
            while(turns-->0)
            {
               for(int i=0; i < 6; i++)
               {
                  int dex = (i+head)%6;
                  arr[dex] = min(arr[dex], arr[(dex+1)%6]+arr[(dex+5)%6]);
               }
               head++;
            }
            long res = 0L;
            if(X > 0 && Y > 0)
            {
               long min = min(X, Y);
               res += min*arr[0];
               X -= min;   Y -= min;
            }
            else if(X < 0 && Y < 0)
            {
               long min = min(-1*X, -1*Y);
               res += min*arr[3];
               X += min;   Y += min;
            }
            if(X > 0)
               res += X*arr[5];
            else
               res += -1*X*arr[2];
            if(Y > 0)
               res += Y*arr[1];
            else
               res += -1*Y*arr[4];
            sb.append(res+"\n");
         }
         System.out.print(sb);
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
Shining through the city with a little funk and soul
*/
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         while(T-->0)
         {
            st = new StringTokenizer(infile.readLine());
            long X = Long.parseLong(st.nextToken());
            long Y = Long.parseLong(st.nextToken());
            st = new StringTokenizer(infile.readLine());
            long[] arr = new long[6];
            for(int i=0; i < 6; i++)
               arr[i] = Long.parseLong(st.nextToken());
            int turns = 3;
            while(turns-->0)
               for(int i=0; i < 6; i++)
                  arr[i] = min(arr[i], arr[(i+1)%6]+arr[(i+5)%6]);
            long res = 0L;
            if(X > 0 && Y > 0)
            {
               long min = min(X, Y);
               res += min*arr[0];
               X -= min;   Y -= min;
            }
            else if(X > 0 && Y < 0)
            {

            }
            else if(X < 0 && Y > 0)
            {

            }
            else if(X < 0 && Y < 0)
            {

            }
            if(X > 0)
               res += X*arr[5];
            else
               res += -1*X*arr[2];
            if(Y > 0)
               res += Y*arr[1];
            else
               res += -1*Y*arr[4];
            sb.append(res+"\n");
         }
         System.out.print(sb);
      }
   }


import java.util.*;
import java.io.*;

public class _1421D {
    static int[] MODS = {1000000007, 998244353};
    static int MOD = MODS[0];

    public static void main(String[] args) {
        sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        while (t-- > 0) {
            long a = sc.nextLong();
            long b = sc.nextLong();
            long[] cost = new long[7];
            for (int i = 1; i <= 6; i++) {
                cost[i] = sc.nextLong();
            }
            long min = Long.MAX_VALUE;
            int[] tests = {12, 13, 15, 16, 23, 24, 26, 34, 35, 45, 46, 56};
            for (int i = 0; i < tests.length; i++) {
                Pair x = find(tests[i], a, b);
                if (x.a < 0 || x.b < 0) {
                    continue;
                }
                int cost1 = (tests[i] / 10) % 10;
                int cost2 = (tests[i] % 10);
                long sum = x.a * cost[cost1] + x.b * cost[cost2];
                min = Math.min(min, sum);
            }
            out.println(min);
        }
        out.close();
    }

    static Pair find(int query, long a, long b) {
        if (query == 12) {
            return new Pair(a, -a+b);
        }
        if (query == 13) {
            return new Pair(b, -a+b);
        }
        if (query == 15) {
            return new Pair(a, a-b);
        }
        if (query == 16) {
            return new Pair(b, a-b);
        }
        if (query == 23) {
            return new Pair(b, -a);
        }
        if (query == 24) {
            return new Pair(-a+b, -a);
        }
        if (query == 26) {
            return new Pair(b, a);
        }
        if (query == 34) {
            return new Pair(-a+b, -b);
        }
        if (query == 35) {
            return new Pair(-a, -b);
        }
        if (query == 45) {
            return new Pair(-a, a-b);
        }
        if (query == 46) {
            return new Pair(-b, a-b);
        }
        if (query == 56) {
            return new Pair(-b, a);
        }
        return null;
    }

    static class Pair {
        long a, b;
        Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    public static int[] sort(int[] arr) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            list.add(arr[i]);
        }
        Collections.sort(list);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
        return arr;
    }

    public static void scan(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
    }

    public static MyScanner sc;
    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static int MOD = 1000000007;

    // After writing solution, quick scan for:
    //   array out of bounds
    //   special cases e.g. n=1?
    //
    // Big numbers arithmetic bugs:
    //   int overflow
    //   sorting, or taking max, after MOD
    void solve() throws IOException {
        int T = ri();
        for (int Ti = 0; Ti < T; Ti++) {
            long[] xy = rll(2);
            long x = xy[0];
            long y = xy[1];
            long[] cost = rll(6);
            long[][] dirs = new long[][]{
                {1, 1}, {0, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, 0}
            };

            if (x == 0 && y == 0) {
                pw.println("0");
                continue;
            }

            // ATTEMPT 1: conjecture that at most 2 directions ever needed
            long ans = Long.MAX_VALUE;
            // 1 direction
            for (int i = 0; i < 6; i++) {
                long a = dirs[i][0];
                long c = dirs[i][1];
                if (x != 0) {
                    if (a == 0) continue;
                    long times = x / a;
                    if (c * times != y) continue;
                    if (times < 0) continue;
                    ans = Math.min(ans, times * cost[i]);
                } else {
                    if (c == 0) continue;
                    long times = y / c;
                    if (a * times != x) continue;
                    if (times < 0) continue;
                    ans = Math.min(ans, times * cost[i]);
                }
            }

            for (int i = 0; i < 6; i++) {
                long a = dirs[i][0];
                long c = dirs[i][1];
                for (int j = 0; j < 6; j++) {
                    if (i == j) continue;
                    long b = dirs[j][0];
                    long d = dirs[j][1];
                    long det = a*d - b*c;
                    if (det == 0) continue;

                    long A = x * d - y * b;
                    long B = -x * c + a * y;
                    if (A < 0 || B < 0 || A % det != 0 || B % det != 0) continue;
                    ans = Math.min(ans, A * cost[i] + B * cost[j]);
                }
            }
            pw.println(ans);
        }
    }

    // Template code below

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        Main m = new Main();
        m.solve();
        m.close();
    }

    void close() throws IOException {
        pw.flush();
        pw.close();
        br.close();
    }

    int ri() throws IOException {
        return Integer.parseInt(br.readLine().trim());
    }

    long rl() throws IOException {
        return Long.parseLong(br.readLine().trim());
    }

    int[] ril(int n) throws IOException {
        int[] nums = new int[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            int sign = 1;
            c = br.read();
            int x = 0;
            if (c == '-') {
                sign = -1;
                c = br.read();
            }
            while (c >= '0' && c <= '9') {
                x = x * 10 + c - '0';
                c = br.read();
            }
            nums[i] = x * sign;
        }
        while (c != '\n' && c != -1) c = br.read();
        return nums;
    }

    long[] rll(int n) throws IOException {
        long[] nums = new long[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            int sign = 1;
            c = br.read();
            long x = 0;
            if (c == '-') {
                sign = -1;
                c = br.read();
            }
            while (c >= '0' && c <= '9') {
                x = x * 10 + c - '0';
                c = br.read();
            }
            nums[i] = x * sign;
        }
        while (c != '\n' && c != -1) c = br.read();
        return nums;
    }

    int[] rkil() throws IOException {
        int sign = 1;
        int c = br.read();
        int x = 0;
        if (c == '-') {
            sign = -1;
            c = br.read();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = br.read();
        }
        return ril(x);
    }

    long[] rkll() throws IOException {
        int sign = 1;
        int c = br.read();
        int x = 0;
        if (c == '-') {
            sign = -1;
            c = br.read();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = br.read();
        }
        return rll(x);
    }

    char[] rs() throws IOException {
        return br.readLine().toCharArray();
    }

    void sort(int[] A) {
        Random r = new Random();
        for (int i = A.length-1; i > 0; i--) {
            int j = r.nextInt(i+1);
            int temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
        Arrays.sort(A);
    }
}