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

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static long ncr(int n, int k)
   	 {

     		  long res = 1;
  		   // Since C(n, k) = C(n, n-k)
 		       if (k > n - k) {
     		       k = n - k;
      		  }
  		  // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
     		   for (int i = 0; i < k; ++i) {
        		    res *= (n - i);
         		   res /= (i + 1);
     		   }
  		  return res;
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	//double d=Math.sqrt(Math.pow(Math.abs(x2-x1),2)+Math.pow(Math.abs(y2-y1),2));
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		int t = nextInt();
		while(t-->0){
			//long n = nextLong();
			//String s= nextToken();
			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];
			//char[] c=nextToken().toCharArray();

		int x1 = nextInt();
		int y1 = nextInt();
		int z1 = nextInt();
		int x2 = nextInt();
		int y2 = nextInt();
		int z2 = nextInt();
		//int n=x1+y1+z1;
		int c=0;
		while(z1-->0&&y2-->0){
		    c+=2;
		}
		while(z2-->0&&z1-->0){
		//   continue;
		}
		while(z2-->0&&x1-->0){
		  // continue;
	    }
		while(z2-->0&&y1-->0){
		   c-=2;
	    }
		writer.println(c);
		}
	}
}


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

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static long ncr(int n, int k)
   	 {

     		  long res = 1;
  		   // Since C(n, k) = C(n, n-k)
 		       if (k > n - k) {
     		       k = n - k;
      		  }
  		  // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
     		   for (int i = 0; i < k; ++i) {
        		    res *= (n - i);
         		   res /= (i + 1);
     		   }
  		  return res;
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	//double d=Math.sqrt(Math.pow(Math.abs(x2-x1),2)+Math.pow(Math.abs(y2-y1),2));
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		int t = nextInt();
		while(t-->0){
			//long n = nextLong();
			//String s= nextToken();
			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];
			//char[] c=nextToken().toCharArray();

		int x1 = nextInt();
		int y1 = nextInt();
		int z1 = nextInt();
		int x2 = nextInt();
		int y2 = nextInt();
		int z2 = nextInt();

		//int n=x1+y1+z1;
		int c=0;

		int d=Math.min(z1,y2);
		c+=(2*d);
		z1-=d;
		y2-=d;

		d=Math.min(z1,z2);
		z2-=d;
		z1-=d;

	    d=Math.min(z2,x1);
	    z2-=d;
	    x1-=d;
	    //writer.println(z2);
		while(z2>0&&y1>0){
		   c-=2;
		   z2--;
		   y1--;
		   //writer.println(z2);
	    }
	    d=Math.min(y1,z2);
	    c-=(2*d);
	    writer.println(c);
		}
	}
}


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

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static long ncr(int n, int k)
   	 {

     		  long res = 1;
  		   // Since C(n, k) = C(n, n-k)
 		       if (k > n - k) {
     		       k = n - k;
      		  }
  		  // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
     		   for (int i = 0; i < k; ++i) {
        		    res *= (n - i);
         		   res /= (i + 1);
     		   }
  		  return res;
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	//double d=Math.sqrt(Math.pow(Math.abs(x2-x1),2)+Math.pow(Math.abs(y2-y1),2));
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		int t = nextInt();
		while(t-->0){
			//long n = nextLong();
			//String s= nextToken();
			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];
			//char[] c=nextToken().toCharArray();

		int x1 = nextInt();
		int y1 = nextInt();
		int z1 = nextInt();
		int x2 = nextInt();
		int y2 = nextInt();
		int z2 = nextInt();
		int n=x1+y1+z1;
		int c=0;
		while(z1-->0&&y2-->0){
		    c+=2;
		}

		    while(z2-->0&&z1-->0){
		        continue;
		    }
		    while(z2-->0&&x1-->0){
		        continue;
		    }
		    while(z2-->0&&y1-->0){
		        c-=2;
		    }

		 writer.println(c);

		 }
	}
}


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

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static long ncr(int n, int k)
   	 {

     		  long res = 1;
  		   // Since C(n, k) = C(n, n-k)
 		       if (k > n - k) {
     		       k = n - k;
      		  }
  		  // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
     		   for (int i = 0; i < k; ++i) {
        		    res *= (n - i);
         		   res /= (i + 1);
     		   }
  		  return res;
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	//double d=Math.sqrt(Math.pow(Math.abs(x2-x1),2)+Math.pow(Math.abs(y2-y1),2));
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		int t = nextInt();
		while(t-->0){
			//long n = nextLong();
			//String s= nextToken();
			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];
			//char[] c=nextToken().toCharArray();

		int x1 = nextInt();
		int y1 = nextInt();
		int z1 = nextInt();
		int x2 = nextInt();
		int y2 = nextInt();
		int z2 = nextInt();

		//int n=x1+y1+z1;
		int c=0;
		while(z1>0&&y2>0){
		    c+=2;
		    z1--;
		    y2--;
		}
		while(z2>0&&z1>0){
		//   continue;
		z2--;
		z1--;
		}
		while(z2>0&&x1>0){
		  // continue;
		  z2--;
		  x1--;
	    }
	    //writer.println(z2);
		while(z2>0&&y1>0){
		   c-=2;
		   z2--;
		   y1--;
		   //writer.println(z2);
	    }
		writer.println(c);
		}
	}
}


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

public class CF1401B {
    static FastScanner fs;
    static PrintWriter out;

    public static void main(String[] args) {
        fs = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int t = fs.nextInt();
        for(long tc=0; tc<t; tc++) {
            int[] a = new int[3];
            int[] b = new int[3];
            for (int i = 0; i < 3; i++) {
                a[i] = fs.nextInt();
            }
            for (int i = 0; i < 3; i++) {
                b[i] = fs.nextInt();
            }
            long ans = Math.min(a[2], b[1]) * 2;
            a[2] -= ans;
            b[1] -= ans;
            if(b[1] > 0) {
                int val = Math.min(b[1], a[0] + a[1]);
                b[1] -= val;
                if(val > a[0]) {
                    val -= a[0];
                    a[1] -= val;
                }

            }
            if(a[1] > 0) {
                int val = Math.min(a[1], b[0]);
                a[1] -= val;
                b[0] -= val;
            }
            if(a[1] > 0) {
                ans -= Math.min(a[1], b[2]) * 2;
            }
            out.println(ans);
        }
        out.close();
    }

    private static class FastScanner {
        BufferedReader bf;
        StringTokenizer st;
        public FastScanner() {
            this.bf = new BufferedReader(new InputStreamReader(System.in));
            this.st = new StringTokenizer("");
        }
        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    this.st = new StringTokenizer(this.bf.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return this.st.nextToken();
        }

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

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

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

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


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

public class CF1401B {
    static FastScanner fs;
    static PrintWriter out;

    public static void main(String[] args) {
        fs = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int t = fs.nextInt();
        for(long tc=0; tc<t; tc++) {
            int[] a = new int[3];
            int[] b = new int[3];
            for (int i = 0; i < 3; i++) {
                a[i] = fs.nextInt();
            }
            for (int i = 0; i < 3; i++) {
                b[i] = fs.nextInt();
            }
            long ans = 0;
            ans += Math.min(a[2], b[1]) * 2;
            a[2] -= ans;
            b[1] -= ans;
            if(b[1] > 0) {
                int val = Math.min(b[1], a[0] + a[1]);
                b[1] -= val;
                val -= a[1];
                if(val < 0) a[1] = -val;
                else if(val == 0) a[1] = 0;
                else {
                    a[1] = 0;
                    a[0] -= val;
                }
            }
            if(a[1] > 0) {
                int val = Math.min(a[1], b[0]);
                a[1] -= val;
                b[0] -= val;
            }
            if(a[1] > 0) {
                ans -= Math.min(a[1], b[2]) * 2;
            }
            out.println(ans);
        }
        out.close();
    }

    private static class FastScanner {
        BufferedReader bf;
        StringTokenizer st;
        public FastScanner() {
            this.bf = new BufferedReader(new InputStreamReader(System.in));
            this.st = new StringTokenizer("");
        }
        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    this.st = new StringTokenizer(this.bf.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return this.st.nextToken();
        }

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

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

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

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


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

public class CF1401B {
    static FastScanner fs;
    static PrintWriter out;

    public static void main(String[] args) {
        fs = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int t = fs.nextInt();
        for(long tc=0; tc<t; tc++) {
            int[] a = new int[3];
            int[] b = new int[3];
            for (int i = 0; i < 3; i++) {
                a[i] = fs.nextInt();
            }
            for (int i = 0; i < 3; i++) {
                b[i] = fs.nextInt();
            }
            int v21 = Math.min(a[2], b[1]);
            a[2] -= v21;
            b[1] -= v21;
            int ans = 2*v21;
            int v11 = Math.min(a[1], b[1]);
            a[1] -= v11;
            b[1] -= v11;
            int v10 = Math.min(a[1], b[0]);
            a[1] -= v10;
            b[0] -= v10;
            ans -= Math.min(a[1], b[2]) * 2;

            out.println(ans);
        }
        out.close();
    }

    private static class FastScanner {
        BufferedReader bf;
        StringTokenizer st;
        public FastScanner() {
            this.bf = new BufferedReader(new InputStreamReader(System.in));
            this.st = new StringTokenizer("");
        }
        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    this.st = new StringTokenizer(this.bf.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return this.st.nextToken();
        }

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

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

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

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


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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(buf.readLine());
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<t;i++)
		{
		    String st1[]=(buf.readLine()).split(" ");
		    int x1=Integer.parseInt(st1[0]);
		    int y1=Integer.parseInt(st1[1]);
		    int z1=Integer.parseInt(st1[2]);
		    String st2[]=(buf.readLine()).split(" ");
		    int x2=Integer.parseInt(st2[0]);
		    int y2=Integer.parseInt(st2[1]);
		    int z2=Integer.parseInt(st2[2]);
		    int a[]=new int[x1+y1+z1];
		    int b[]=new int[x2+y2+z2];

		    for(int j=0;j<z1;j++)
		    a[j]=2;
		    for(int j=z1;j<z1+y1;j++)
		    a[j]=1;
		    Arrays.fill(b,2);
		    for(int j=0;j<y2;j++)
		    b[j]=1;
		    for(int j=y2;j<y2+x2;j++)
		    b[j]=0;

		    long sum=0;
		    for(int j=0;j<a.length;j++)
		    {
		       if(a[j]>b[j])
		       sum=sum+(a[j]*b[j]);
		       else if(a[j]<b[j])
		       sum=sum-(a[j]*b[j]);
		       else
		       sum=sum+0;
		    }
		    sb.append(sum+"\n");

		    /*for(int j=0;j<a.length;j++)
		    System.out.print(a[j]+" ");
		    System.out.println();
		    for(int j=0;j<b.length;j++)
		    System.out.print(b[j]+" ");
		    System.out.println();
		    */
		}
		System.out.println(sb);
	}
}


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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(buf.readLine());
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<t;i++)
		{
		    String st1[]=(buf.readLine()).split(" ");
		    int x1=Integer.parseInt(st1[0]);
		    int y1=Integer.parseInt(st1[1]);
		    int z1=Integer.parseInt(st1[2]);
		    String st2[]=(buf.readLine()).split(" ");
		    int x2=Integer.parseInt(st2[0]);
		    int y2=Integer.parseInt(st2[1]);
		    int z2=Integer.parseInt(st2[2]);
		    int a[]=new int[x1+y1+z1];
		    int b[]=new int[x2+y2+z2];

		    for(int j=0;j<z1;j++)
		    a[j]=2;
		    for(int j=z1;j<z1+y1;j++)
		    a[j]=1;
		    for(int j=0;j<y2;j++)
		    b[j]=1;
		    for(int j=y2;j<y2+x2;j++)
		    b[j]=0;
		    for(int j=y2+x2;j<x2+y2+z2;j++)
		    b[j]=2;
		    long sum=0;
		    for(int j=0;j<a.length;j++)
		    {
		       if(a[j]>b[j])
		       sum=sum+(a[j]*b[j]);
		       else if(a[j]<b[j])
		       sum=sum-(a[j]*b[j]);
		       else
		       sum=sum+0;
		    }
		    sb.append(sum+"\n");
		}
		System.out.println(sb);
	}
}


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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(buf.readLine());
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<t;i++)
		{
		    String st1[]=(buf.readLine()).split(" ");
		    int x1=Integer.parseInt(st1[0]);
		    int y1=Integer.parseInt(st1[1]);
		    int z1=Integer.parseInt(st1[2]);
		    String st2[]=(buf.readLine()).split(" ");
		    int x2=Integer.parseInt(st2[0]);
		    int y2=Integer.parseInt(st2[1]);
		    int z2=Integer.parseInt(st2[2]);
		    int cnt_a[]=new int[3];
		    int cnt_b[]=new int[3];
		    cnt_a[0]=x1;cnt_a[1]=y1;cnt_a[2]=z1;
		    cnt_b[0]=x2;cnt_b[1]=y2;cnt_b[2]=z2;

		    int no_2=Math.min(cnt_a[2],cnt_b[1]);
		    cnt_a[2]=cnt_a[2]-no_2;
		    cnt_b[1]=cnt_b[1]-no_2;

		    int no_01=Math.min(cnt_a[1],cnt_b[1]);
		    cnt_a[1]-=no_01;
		    cnt_b[1]-=no_01;
		    int no_02=Math.min(cnt_a[2],cnt_b[2]);
		    cnt_a[2]-=no_02;
		    cnt_b[2]-=no_02;
		    int no_03=Math.min(cnt_b[2],cnt_a[0]);
		    cnt_b[2]-=no_03;
		    cnt_a[0]-=no_03;
		    int no_04=Math.min(cnt_a[1],cnt_b[0]);
		    cnt_a[1]-=no_04;
		    cnt_b[0]-=no_04;
		    int no_neg2=Math.min(cnt_a[1],cnt_b[2]);
		    long sum=(no_2*2)-(no_neg2*2);
		    sb.append(sum+"\n");
		}
		System.out.println(sb);
	}
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                y2=0;
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2)){
                p.println("*");
                ans=ans-((y1-(x2+y2))*2);
            }
            System.out.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=0;
            long s=x1+y1+z1;
            for(int i=0;i<s;i++){
                if(z1!=0 && y2!=0){
                    z1--;
                    y2--;
                    ans+=2;
                }
                else if(z1==0 && x1==0 && y2==0 && z2!=0){
                    ans=ans-2;
                    z2--;
                }
                else{
                    if(z1==0){
                        x1--;
                    }
                    else{
                        z1--;
                    }
                    if(y2==0){
                        z2--;
                    }
                    else{
                        y2--;
                    }
                }
            }
            p.println(ans);
            /*long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                if(z2>z1-y2){
                    z2=z2-(z1-y2);
                    y2=0;
                }
                else if(z2==(z1-y2)){
                    z2=0;
                    y2=0;
                }
                else{
                    x2=x2-(z1-y2+z2);
                    z2=0;
                    y2=0;
                }
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2))
                ans=ans-((y1-(x2+y2))*2);*/

        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                if(z2>z1-y2){
                    z2=z2-(z1-y2);
                    y2=0;
                }
                else if(z2==(z1-y2)){
                    z2=0;
                    y2=0;
                }
                else{
                    x2=x2-(z1-y2+z2);
                    z2=0;
                    y2=0;
                }
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2))
                ans=ans-((y1-(x2+y2))*2);
            if(ans<0)
                p.println("0");
            else
                p.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                if(z2>z1-y2){
                    z2=z2-(z1-y2);
                    y2=0;
                }
                else if(z2==(z1-y2)){
                    z2=0;
                    y2=0;
                }
                else{
                    x2=x2-(z1-y2+z2);
                    z2=0;
                    y2=0;
                }
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2))
                ans=ans-((y1-(x2+y2))*2);
            p.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            /*long ans=0;
            long s=x1+y1+z1;
            for(int i=0;i<s;i++){
                if(z1!=0 && y2!=0){
                    z1--;
                    y2--;
                    ans+=2;
                }
                else if(z1==0 && x1==0 && y2==0 && z2!=0){
                    ans=ans-2;
                    z2--;
                }
                else{
                    if(z1==0){
                        x1--;
                    }
                    else{
                        z1--;
                    }
                    if(y2==0){
                        z2--;
                    }
                    else{
                        y2--;
                    }
                }
            }
            p.println(ans);*/
            long ans=Math.min(z1,y2)*2;
            p.println(ans);
            if(z1>y2){
                if(z2>z1-y2){
                    z2=z2-(z1-y2);
                    y2=0;
                }
                else if(z2==(z1-y2)){
                    z2=0;
                    y2=0;
                }
                else{
                    x2=x2-(z1-y2-z2);
                    z2=0;
                    y2=0;
                }
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2)){
                p.println("*");
                ans=ans-((y1-(x2+y2))*2);
            }
            p.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            /*long ans=0;
            long s=x1+y1+z1;
            for(int i=0;i<s;i++){
                if(z1!=0 && y2!=0){
                    z1--;
                    y2--;
                    ans+=2;
                }
                else if(z1==0 && x1==0 && y2==0 && z2!=0){
                    ans=ans-2;
                    z2--;
                }
                else{
                    if(z1==0){
                        x1--;
                    }
                    else{
                        z1--;
                    }
                    if(y2==0){
                        z2--;
                    }
                    else{
                        y2--;
                    }
                }
            }
            p.println(ans);*/
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                if(z2>z1-y2){
                    z2=z2-(z1-y2);
                    y2=0;
                }
                else if(z2==(z1-y2)){
                    z2=0;
                    y2=0;
                }
                else{
                    x2=x2-(z1-y2-z2);
                    z2=0;
                    y2=0;
                }
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2)){
                p.println("*");
                ans=ans-((y1-(x2+y2))*2);
            }
            p.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                y2=0;
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2)){
                ans=ans-((y1-(x2+y2))*2);
            }
            System.out.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                if(z2>z1-y2){
                    z2=z2-(z1-y2);
                    y2=0;
                }
                else if(z2==(z1-y2)){
                    z2=0;
                    y2=0;
                }
                else{
                    x2=x2-(z1-y2-z2);
                    z2=0;
                    y2=0;
                }
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2)){
                p.println("*");
                ans=ans-((y1-(x2+y2))*2);
            }
            p.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
public class vivek{
    static class FastReader
    {

        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            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();
        }

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

        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;
        }

        int[] nextArray(int rows)
        {
            int arr[] = new int[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextInt();
            return arr;
        }

        long[] nextLongArray(int rows)
        {
            long arr[] = new long[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = nextLong();
            return arr;
        }

        char[] nextCharArray(int rows)
        {
            char arr[] = new char[rows];
            for (int i = 0; i < rows; i++)
            arr[i] = next().charAt(0);
            return arr;
        }

        int[][] nextMatrix(int rows, int columns)
        {
            int mat[][] = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    mat[i][j] = nextInt();
                }
            }
            return mat;
        }
    }
    public static void main(String args[]){
        FastReader sc=new FastReader();
        PrintWriter p=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            long x1=sc.nextInt();
            long y1=sc.nextInt();
            long z1=sc.nextInt();
            long x2=sc.nextInt();
            long y2=sc.nextInt();
            long z2=sc.nextInt();
            long ans=Math.min(z1,y2)*2;
            if(z1>y2){
                y2=0;
            }
            else
                y2=y2-z1;
            if(y1>(x2+y2)){
                p.println("*");
                ans=ans-((y1-(x2+y2))*2);
            }
            p.println(ans);
        }
        p.flush();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int t = in.nextInt();

		while (t-- > 0) {

			int x1 = in.nextInt();
			int y1 = in.nextInt();
			int z1 = in.nextInt();

			int x2 = in.nextInt();
			int y2 = in.nextInt();
			int z2 = in.nextInt();

			int ans = 0;
			ans += 2 * Math.min(z1, y2);
			z1 -= Math.min(z1, y2);
			y2 -= Math.min(z1, y2);

			if (z1 > 0) {

				if (z2 >= z1) {
					z2 = z2 - z1;
					z1 = 0;
				} else {
					z2 = 0;
					z1 -= z2;
				}
			}

			if (y1 > x2 + y2) {
				ans -= 2 * (y1 - x2 - y2);
			}
			System.out.println(ans);

		}

		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			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.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int t = in.nextInt();

		while (t-- > 0) {

			int x1 = in.nextInt();
			int y1 = in.nextInt();
			int z1 = in.nextInt();

			int x2 = in.nextInt();
			int y2 = in.nextInt();
			int z2 = in.nextInt();

			int ans = 0;
			int val = Math.min(z1, x2);
			ans += val * 2;
			z1 -= val;
			x2 -= val;
			val = Math.min(y1, y2);
			y1 -= val;
			y2 -= val;
			val = Math.min(y1, x2);
			y1 -= val;
			x2 -= val;
			val = Math.min(y1, z2);
			ans -= val * 2;
			System.out.println(ans);

		}

		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			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.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int t = in.nextInt();

		while (t-- > 0) {

			int x1 = in.nextInt();
			int y1 = in.nextInt();
			int z1 = in.nextInt();

			int x2 = in.nextInt();
			int y2 = in.nextInt();
			int z2 = in.nextInt();

			int ans = 0;
			int val = Math.min(z1, y2);
			ans += val * 2;
			z1 -= val;
			y2 -= val;
			val = Math.min(y1, y2);
			y1 -= val;
			y2 -= val;
			val = Math.min(y1, x2);
			y1 -= val;
			x2 -= val;
			val = Math.min(y1, z2);
			ans -= val * 2;
			System.out.println(ans);

		}

		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			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.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int t = in.nextInt();

		while (t-- > 0) {

			int x1 = in.nextInt();
			int y1 = in.nextInt();
			int z1 = in.nextInt();

			int x2 = in.nextInt();
			int y2 = in.nextInt();
			int z2 = in.nextInt();

			int ans = 0;
			ans += 2 * Math.min(z1, y2);
			z1 -= Math.min(z1, y2);
			y2 -= Math.min(z1, y2);

			if (z1 > 0) {

				if (z2 >= z1) {
					z2 = z2 - z1;
				} else {
					z2 = 0;
					z1 -= z2;
				}
			}

			if (y1 > x2 + y2) {
				ans -= 2 * (y1 - x2 - y2);
			}
			System.out.println(ans);

		}

		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			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.util.*;
import java.io.*;

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long aNonZero = A[1] + A[2];
            long bNonZero = B[1] + B[2];
            if (aNonZero == 0 || bNonZero == 0)
            {
                System.out.println(0);
                continue;
            }
            if (A[1] == B[1] && A[1] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            if (A[2] == B[2] && A[2] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            long sum = 0;
            long aTwo = A[2];
            long bOne = B[1];
            A[2] -= bOne;
            B[1] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[1] < 0)
                B[1] = 0;
            //print();
            long diff = aTwo - A[2];
            sum += 2 * diff;
            long aOne = A[1];
            long bZero = B[0];
            A[1] -= bZero;
            B[0] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[0] < 0)
                B[0] = 0;
            //print();
            long aZero = A[0];
            long bTwo = B[2];
            A[0] -= bTwo;
            B[2] -= aZero;
            if (A[0] < 0)
                A[0] = 0;
            if (B[2] < 0)
                B[2] = 0;
            //print();
            sum -= 2*B[2];
            System.out.println(sum);
        }
    }

    public static void print()
    {
        System.out.println(A[0] + " " + A[1] + " " + A[2]);
        System.out.println(B[0] + " " + B[1] + " " + B[2]);
    }
}


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

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long sum = 0;
            long aTwo = A[2];
            long bOne = B[1];
            A[2] -= bOne;
            B[1] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[1] < 0)
                B[1] = 0;
            long diff = aTwo - A[2];
            sum += diff * 2;
            long aOne = A[1];
            long bZero = B[0];
            A[1] -= bZero;
            B[0] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[0] < 0)
                B[0] = 0;
            aOne = A[1];
            bOne = B[1];
            A[1] -= bOne;
            B[1] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[1] < 0)
                B[1] = 0;
            aTwo = A[2];
            long bTwo = B[2];
            A[2] -= bTwo;
            B[2] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[2] < 0)
                B[2] = 0;
            long aZero = A[0];
            bTwo = B[2];
            A[0] -= bTwo;
            B[2] -= aZero;
            if (A[0] < 0)
                A[0] = 0;
            if (B[2] < 0)
                B[2] = 0;
            aOne = A[1];
            bTwo = B[2];
            A[1] -= bTwo;
            B[2] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[2] < 0)
                B[2] = 0;
            diff = bTwo - B[2];
            sum -= 2 * diff;
            System.out.println(sum);
        }
    }

    public static void print()
    {
        System.out.println(A[0] + " " + A[1] + " " + A[2]);
        System.out.println(B[0] + " " + B[1] + " " + B[2]);
    }
}


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

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long aNonZero = A[1] + A[2];
            long bNonZero = B[1] + B[2];
            if (aNonZero == 0 || bNonZero == 0)
            {
                System.out.println(0);
                continue;
            }
            long sum = 0;
            long aTwo = A[2];
            long bOne = B[1];
            A[2] -= bOne;
            B[1] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[1] < 0)
                B[1] = 0;
            long diff = aTwo - A[2];
            sum += 2 * diff;
            long aOne = A[1];
            long bZero = B[0];
            A[1] -= bZero;
            B[0] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[0] < 0)
                B[0] = 0;
            long aZero = A[0];
            long bTwo = B[2];
            A[0] -= bTwo;
            B[2] -= aZero;
            if (A[0] < 0)
                A[0] = 0;
            if (B[2] < 0)
                B[2] = 0;
            sum -= 2*A[1];
            System.out.println(sum);
        }
    }
}


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

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long aNonZero = A[1] + A[2];
            long bNonZero = B[1] + B[2];
            if (aNonZero == 0 || bNonZero == 0)
            {
                System.out.println(0);
                continue;
            }
            if (A[1] == B[1] && A[1] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            if (A[2] == B[2] && A[2] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            long sum = 0;
            long aTwo = A[2];
            long bOne = B[1];
            A[2] -= bOne;
            B[1] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[1] < 0)
                B[1] = 0;
            //print();
            long diff = aTwo - A[2];
            sum += 2 * diff;
            long aOne = A[1];
            long bZero = B[0];
            A[1] -= bZero;
            B[0] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[0] < 0)
                B[0] = 0;
            //print();
            long aZero = A[0];
            long bTwo = B[2];
            A[0] -= bTwo;
            B[2] -= aZero;
            if (A[0] < 0)
                A[0] = 0;
            if (B[2] < 0)
                B[2] = 0;
            aOne = A[1];
            bTwo = B[2];
            B[2] -= aOne;
            if (B[2] < 0)
                B[2] = 0;
            diff = bTwo - B[2];
            sum -= 2*diff;
            System.out.println(sum);
        }
    }

    public static void print()
    {
        System.out.println(A[0] + " " + A[1] + " " + A[2]);
        System.out.println(B[0] + " " + B[1] + " " + B[2]);
    }
}


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

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long aNonZero = A[1] + A[2];
            long bNonZero = B[1] + B[2];
            if (aNonZero == 0 || bNonZero == 0)
            {
                System.out.println(0);
                continue;
            }
            if (A[1] == B[1] && A[1] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            if (A[2] == B[2] && A[2] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            long sum = 0;
            long aTwo = A[2];
            long bOne = B[1];
            A[2] -= bOne;
            B[1] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[1] < 0)
                B[1] = 0;
            //print();
            long diff = aTwo - A[2];
            sum += 2 * diff;
            long aOne = A[1];
            long bZero = B[0];
            A[1] -= bZero;
            B[0] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[0] < 0)
                B[0] = 0;
            //print();
            aOne = A[1];
            bOne = B[1];
            A[1] -= bOne;
            B[1] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[1] < 0)
                B[1] = 0;
            //print();
            long aZero = A[0];
            long bTwo = B[2];
            A[0] -= bTwo;
            B[2] -= aZero;
            if (A[0] < 0)
                A[0] = 0;
            if (B[2] < 0)
                B[2] = 0;
            //print();
            aTwo = A[2];
            bTwo = B[2];
            A[2] -= bTwo;
            B[2] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[2] < 0)
                B[2] = 0;
            aOne = A[1];
            bTwo = B[2];
            B[2] -= aOne;
            if (B[2] < 0)
                B[2] = 0;
            //print();
            diff = bTwo - B[2];
            sum -= 2*diff;
            System.out.println(sum);
        }
    }

    public static void print()
    {
        System.out.println(A[0] + " " + A[1] + " " + A[2]);
        System.out.println(B[0] + " " + B[1] + " " + B[2]);
    }
}


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

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long aNonZero = A[1] + A[2];
            long bNonZero = B[1] + B[2];
            if (aNonZero == 0 || bNonZero == 0)
            {
                System.out.println(0);
                continue;
            }
            long total = A[0] + A[1] + A[2];
            int[] seqA = new int[(int)total];
            int[] seqB = new int[(int)total];
            long twoA = 0, oneA = 0;
            long oneB = 0, zeroB = 0;
            long sum = 0;
            for (int i = 0; i < total; i++)
            {
                if (twoA < A[2])
                {
                    seqA[i] = 2;
                    twoA++;
                }
                else if (oneA < A[1])
                {
                    seqA[i] = 1;
                    oneA++;
                }
                else
                    seqA[i] = 0;
                if (oneB < B[1])
                {
                    seqB[i] = 1;
                    oneB++;
                }
                else if (zeroB < B[0])
                {
                    seqB[i] = 0;
                    zeroB++;
                }
                else
                    seqB[i] = 2;
                int aVal = seqA[i];
                int bVal = seqB[i];
                if (aVal > bVal)
                    sum += aVal * bVal;
                else if (aVal < bVal)
                    sum += aVal * bVal * -1;
            }
            System.out.println(sum);
        }
    }
}


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

public class TernarySequence {

    static int T;
    static long[] A, B;

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        T = Integer.parseInt(st.nextToken());
        while (T > 0)
        {
            T--;
            A = new long[3];
            B = new long[3];
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                A[i] = Integer.parseInt(st.nextToken());
            st = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++)
                B[i] = Integer.parseInt(st.nextToken());
            long aNonZero = A[1] + A[2];
            long bNonZero = B[1] + B[2];
            if (aNonZero == 0 || bNonZero == 0)
            {
                System.out.println(0);
                continue;
            }
            if (A[1] == B[1] && A[1] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            if (A[2] == B[2] && A[2] == aNonZero)
            {
                System.out.println(0);
                continue;
            }
            long sum = 0;
            long aTwo = A[2];
            long bOne = B[1];
            A[2] -= bOne;
            B[1] -= aTwo;
            if (A[2] < 0)
                A[2] = 0;
            if (B[1] < 0)
                B[1] = 0;
            //print();
            long diff = aTwo - A[2];
            sum += 2 * diff;
            long aOne = A[1];
            long bZero = B[0];
            A[1] -= bZero;
            B[0] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[0] < 0)
                B[0] = 0;
            //print();
            aOne = A[1];
            bOne = B[1];
            A[1] -= bOne;
            B[1] -= aOne;
            if (A[1] < 0)
                A[1] = 0;
            if (B[1] < 0)
                B[1] = 0;
            long aZero = A[0];
            long bTwo = B[2];
            A[0] -= bTwo;
            B[2] -= aZero;
            if (A[0] < 0)
                A[0] = 0;
            if (B[2] < 0)
                B[2] = 0;
            aOne = A[1];
            bTwo = B[2];
            B[2] -= aOne;
            if (B[2] < 0)
                B[2] = 0;
            diff = bTwo - B[2];
            sum -= 2*diff;
            System.out.println(sum);
        }
    }

    public static void print()
    {
        System.out.println(A[0] + " " + A[1] + " " + A[2]);
        System.out.println(B[0] + " " + B[1] + " " + B[2]);
    }
}


import java.util.Scanner;

public class B_After_Editorial {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int t= s.nextInt();
        for(int i=0;i<t;i++){
            int x1= s.nextInt();
            int y1= s.nextInt();
            int z1= s.nextInt();
            int x2= s.nextInt();
            int y2= s.nextInt();
            int z2= s.nextInt();

            int val = Math.min(z1,y2);
            z1= z1-val;
            y2= y2-val;
            int sum = 2*val;
            z1 = z1+x1;

            z2 -= Math.min(z2,z1);
            y1 -= Math.min(y1,x2+y2);

            sum = sum - 2*Math.min(z2,y1);
            System.out.println(sum);
        }
    }
}


import java.util.Scanner;

public class B {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int t= s.nextInt();
        for(int i=0;i<t;i++){
            int x1= s.nextInt();
            int y1= s.nextInt();
            int z1= s.nextInt();
            int x2= s.nextInt();
            int y2= s.nextInt();
            int z2= s.nextInt();

            int sum=0;

            if(z1>y2){
                sum = sum + y2*2;
                z1= z1-y2;

                if(z1+x1<z2){
                    z2 = z2-(x1+z1);
                    sum = sum - 2*Math.min(z2,y1);
                }
            }else{
                sum = sum + z1*2;
                if(x1<z2){
                    z2 = z2-x1;
                    sum = sum - 2*(Math.min(z2,y1));
                }
            }

            System.out.println(sum);
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class D {
    static int mod = 1000000000 + 7;
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        for(int i=0;i<t;i++){
            int n =s.nextInt();
            //creating tree like data structure
            //n+1 because 1 based indexing
            ArrayList<Integer>[] edges = new ArrayList[n+1];
            for(int j=0;j< edges.length;j++){
                edges[j] = new ArrayList<>();
            }
            for(int j=0;j<n-1;j++){
                int u = s.nextInt();
                int v = s.nextInt();

                edges[u].add(v);
                edges[v].add(u);

            }
            int m = s.nextInt();
            ArrayList<Long> p = new ArrayList();
            for(int j=0;j<m;j++){
                p.add((long)s.nextInt());
            }
            //storing chile node from each node assuming 1 as root node
            int[] childCountDp = new int[n+1];
            methodChildCount(1,0,childCountDp,edges);
            ArrayList<Long> edgeFrequencyCount = new ArrayList<>();
            findEachEdgeOccourance(1,0,childCountDp,edges,edgeFrequencyCount, n);

            Collections.sort(edgeFrequencyCount,Collections.reverseOrder());
            Collections.sort(p, Collections.reverseOrder());
            if(edgeFrequencyCount.size()>=p.size()){
                int sizeDiff = edgeFrequencyCount.size()-p.size();
                for(int j=0;j<sizeDiff;j++){
                    p.add(1l);
                }
            }else{
                long prod = p.get(0);
                for(int j=edgeFrequencyCount.size();j<p.size();j++){
                    prod = (prod * p.get(j))%mod;
                }
                p.set(0,prod);
            }
            long ans = 0;
            for(int j=0;j<edgeFrequencyCount.size();j++){
                    ans = ans + (edgeFrequencyCount.get(j)*p.get(j))%mod;
        //        System.out.println(ans  );
                    ans = ans % mod;
          //      System.out.println(ans);
            }

            System.out.println(ans);

        }
    }

    private static void findEachEdgeOccourance(int curr, int last, int[] childCountDp, ArrayList<Integer>[] edges,ArrayList<Long> edgeFrequencyCount, int totalNodes) {
        ArrayList<Integer> edge = edges[curr];
        for(int i=0;i<edge.size();i++){
            int v= edge.get(i);

            if(v==last){
                continue;
            }
            long edgeFreq = childCountDp[v]*((long)totalNodes-childCountDp[v]);
            edgeFrequencyCount.add(edgeFreq);
            findEachEdgeOccourance(v,curr,childCountDp,edges,edgeFrequencyCount,totalNodes);
        }
    }

    public static int methodChildCount(int curr, int last, int[] childCountDp, ArrayList<Integer>[] edges){

        int sum = 0;
        ArrayList<Integer> edgeList = edges[curr];
        for(int i=0;i<edgeList.size();i++){

            int v= edgeList.get(i);
            if(v==last){
                continue;
            }
            sum += methodChildCount(v,curr,childCountDp,edges);
        }

        sum = sum + 1; //including self
        childCountDp[curr] = sum;
        return sum;
    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = in.nextInt();
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int _0 = in.nextInt(), _1 = in.nextInt(), _2 = in.nextInt();
            int __0 = in.nextInt(), __1 = in.nextInt(), __2 = in.nextInt();

            out.println(go(_0, _1, _2, __0, __1, __2));
        }

        private long go(int _0, int _1, int _2, int __0, int __1, int __2)
        {
            if (_2 > 0)
            {
                if (__1 > 0)
                {
                    if (_2 >= __1)
                    {
                        return (long) (2 * __1) + go(_0, _1, _2 - __1, __0, 0, __2);
                    } else
                    {
                        return (long) (2 * _2) + go(_0, _1, 0, __0, __1 - _2, __2);
                    }
                } else if (__2 > 0)
                {
                    if (_2 >= __2)
                    {
                        return go(_0, _1, _2 - __2, __0, __1, 0);
                    } else
                    {
                        return go(_0, _1, 0, __0, __1, __2 - _2);
                    }
                }
            } else if (_0 > 0)
            {
                if (__2 > 0)
                {
                    if (_0 >= __2)
                    {
                        return go(_0 - __2, _1, _2, __0, __1, 0);
                    } else
                    {
                        return go(0, _1, _2, __0, __1, __2 - _0);
                    }
                }
            } else if (_1 > 0)
            {
                if (__1 > 0)
                {
                    if (_1 >= __1)
                    {
                        return go(_0, _1 - __1, _2, __0, 0, __2);
                    } else
                    {
                        return go(_0, 0, _2, __0, __1 - _1, __2);
                    }
                } else if (__0 > 0)
                {
                    if (_1 >= __0)
                    {
                        return go(_0, _1 - __0, _2, 0, __1, __2);
                    } else
                    {
                        return go(_0, 0, _2, __0 - _1, __1, __2);
                    }
                } else if (__2 > 0)
                {
                    if (_1 >= __2)
                    {
                        return -(long) (2 * __2) + go(_0, _1 - __2, _2, __0, __1, 0);
                    } else
                    {
                        return -(long) (2 * _1) + go(_0, 0, _2, __0, __1, __2 - _1);
                    }
                }
            } else
            {
                return 0;
            }
            return 0;
        }

    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = in.nextInt();
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int _0 = in.nextInt(), _1 = in.nextInt(), _2 = in.nextInt();
            int __0 = in.nextInt(), __1 = in.nextInt(), __2 = in.nextInt();

            out.println(go(_0, _1, _2, __0, __1, __2));
        }

        private long go(int _0, int _1, int _2, int __0, int __1, int __2)
        {
            if (_2 > 0)
            {
                if (__1 > 0)
                {
                    if (_2 >= __1)
                    {
                        return (long) Math.pow(2, __1) + go(_0, _1, _2 - __1, __0, 0, __2);
                    } else
                    {
                        return (long) Math.pow(2, _2) + go(_0, _1, 0, __0, __1 - _2, __2);
                    }
                } else if (__2 > 0)
                {
                    if (_2 >= __2)
                    {
                        return go(_0, _1, _2 - __2, __0, __1, 0);
                    } else
                    {
                        return go(_0, _1, 0, __0, __1, __2 - _2);
                    }
                }
            } else if (_0 > 0)
            {
                if (__2 > 0)
                {
                    if (_0 >= __2)
                    {
                        return go(_0 - __2, _1, _2, __0, __1, 0);
                    } else
                    {
                        return go(0, _1, _2, __0, __1, __2 - _0);
                    }
                }
            } else if (_1 > 0)
            {
                if (__1 > 0)
                {
                    if (_1 >= __1)
                    {
                        return go(_0, _1 - __1, _2, __0, 0, __2);
                    } else
                    {
                        return go(_0, 0, _2, __0, __1 - _1, __2);
                    }
                } else if (__0 > 0)
                {
                    if (_1 >= __0)
                    {
                        return go(_0, _1 - __0, _2, 0, __1, __2);
                    } else
                    {
                        return go(_0, 0, _2, __0 - _1, __1, __2);
                    }
                } else if (__2 > 0)
                {
                    if (_1 >= __2)
                    {
                        return -(long) Math.pow(2, __2) + go(_0, _1 - __2, _2, __0, __1, 0);
                    } else
                    {
                        return -(long) Math.pow(2, _1) + go(_0, 0, _2, __0, __1, __2 - _1);
                    }
                }
            } else
            {
                return 0;
            }
            return 0;
        }

    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = in.nextInt();
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int _0 = in.nextInt(), _1 = in.nextInt(), _2 = in.nextInt();
            int __0 = in.nextInt(), __1 = in.nextInt(), __2 = in.nextInt();

            out.println(go(_0, _1, _2, __0, __1, __2));

        }

        private long go(int _0, int _1, int _2, int __0, int __1, int __2)
        {
            if (_2 > 0)
            {
                if (__1 > 0)
                {
                    if (_2 >= __1)
                    {
                        return (long) Math.pow(2, __1) + go(_0, _1, _2 - __1, __0, 0, __2);
                    } else
                    {
                        return (long) Math.pow(2, _2) + go(_0, _1, 0, __0, __1 - _2, __2);
                    }
                } else if (__2 > 0)
                {
                    if (_2 >= __2)
                    {
                        return go(_0, _1, _2 - __2, __0, __1, 0);
                    } else
                    {
                        return go(_0, _1, 0, __0, __1, __2 - _2);
                    }
                }
            } else if (_1 > 0)
            {
                if (__1 > 0)
                {
                    if (_1 >= __1)
                    {
                        return go(_0, _1 - __1, _2, __0, 0, __2);
                    } else
                    {
                        return go(_0, 0, _2, __0, __1 - _1, __2);
                    }
                } else if (__0 > 0)
                {
                    if (_1 >= __0)
                    {
                        return go(_0, _1 - __0, _2, 0, __1, __2);
                    } else
                    {
                        return go(_0, 0, _2, __0 - _1, __1, __2);
                    }
                } else if (__2 > 0)
                {
                    if (_1 >= __2)
                    {
                        return -(long) Math.pow(2, __2) + go(_0, _1 - __2, _2, __0, __1, 0);
                    } else
                    {
                        return -(long) Math.pow(2, _1) + go(_0, 0, _2, __0, __1, __2 - _1);
                    }
                }
            } else
            {
                return 0;
            }
            return 0;
        }

    }
}


//Problem:  ()
//Status: Not Accepted

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

public class ProblemB {
    private static InputReader infile = new InputReader();
    private static PrintWriter outfile = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int[] aIndex = new int[] {2, 0, 0, 0, 1, 1, 2, 2, 1};
        int[] bIndex = new int[] {1, 0, 1, 2, 0, 1, 0, 2, 2};
        int[] values = new int[] {2, 0, 0, 0, 0, 0, 0, 0, -2};
        int numTestCases = infile.nextInt();
        for(int t = 1; t <= numTestCases; t++) {
            int[] a = new int[] {infile.nextInt(), infile.nextInt(), infile.nextInt()};
            int[] b = new int[] {infile.nextInt(), infile.nextInt(), infile.nextInt()};
            int sum = 0;
            for(int i = 0; i < 9; i++) {
                int min = Math.min(a[aIndex[i]], b[bIndex[i]]);
                sum += min * values[i];
                a[aIndex[i]] -= min;
                b[bIndex[i]] -= min;
            }
            outfile.println(sum);
        }

        infile.close();
        outfile.close();
    }

    static class InputReader {
        private static BufferedReader infile;
        private static StringTokenizer st;

        public InputReader() {
            infile = new BufferedReader(new InputStreamReader(System.in));
            st = null;
        }

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

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

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

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

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

        public void close() throws IOException {
            infile.close();
        }
    }
}