//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, 1, 1, 0, 2, 2, 0, 0, 1};
        int[] bIndex = new int[] {1, 0, 1, 2, 2, 0, 1, 0, 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();
        }
    }
}


//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 < 8; i++) {
                while(a[aIndex[i]] > 0 && b[bIndex[i]] > 0) {
                    sum += values[i];
                    a[aIndex[i]]--;
                    b[bIndex[i]]--;
                }
            }
            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();
        }
    }
}


import java.util.*;

public class Main{

public static void main(String[] args) {

   Scanner scn=new Scanner(System.in);
   int t=scn.nextInt();
   while(t-->0){
       long sum=0;
       long[] a = new long[3];
       long[] b = new long[3];
       for(int i=0;i<3;i++){
           a[i]=scn.nextLong();
       }
       for(int i=0;i<3;i++){
           b[i]=scn.nextLong();
       }
       long val = a[2] - b[1];
       if(val>0){
           sum+=b[1]*2;
           a[2]-=b[1];
           b[1]=0;
       }
       else if(val<0){
           sum+=a[2]*2;
           b[1]-=a[2];
           a[2]=0;
       }
       else{
           sum+=a[2]*2;
           a[2]=0;
           b[1]=0;
       }

      val = a[1] - b[0];
      if(val>0){
          a[1]-=b[0];
          b[0]=0;
      }
      else if(val<0){
          b[0]-=a[1];
          a[1]=0;
      }
      else{
          a[1]=0;
          b[0]=0;
      }
      val = a[0] - b[2];
      if(val>0){
          a[0]-=b[2];
          b[2]=0;
      }
      else if(val<0){
          b[2]-=a[0];
          a[0]=0;
      }
      else{
          a[0]=0;
          b[2]=0;
      }
      val = a[1] - b[2];
      if(val==0){
       System.out.println(sum);
      }
      else{
          sum-=2*a[1];
          System.out.println(sum);
      }
   }

 }
}


import java.util.*;

public class Main{

public static void main(String[] args) {

   Scanner scn=new Scanner(System.in);
   int t=scn.nextInt();
   while(t-->0){
       long sum=0;
       long[] a = new long[3];
       long[] b = new long[3];
       for(int i=0;i<3;i++){
           a[i]=scn.nextLong();
       }
       for(int i=0;i<3;i++){
           b[i]=scn.nextLong();
       }
       long val = a[2] - b[1];
       if(val>0){
           sum+=b[1]*2;
           a[2]-=b[1];
           b[1]=0;
       }
       else if(val<0){
           sum+=a[2]*2;
           b[1]-=a[2];
           a[2]=0;
       }
       else{
           sum+=a[2]*2;
           a[2]=0;
           b[1]=0;
       }

      val = a[1] - b[0];
      if(val>0){
          a[1]-=b[0];
          b[0]=0;
      }
      else if(val<0){
          b[0]-=a[1];
          a[1]=0;
      }
      else{
          a[1]=0;
          b[0]=0;
      }
      val = a[0] - b[2];
      if(val>0){
          a[0]-=b[2];
          b[2]=0;
      }
      else if(val<0){
          b[2]-=a[0];
          a[0]=0;
      }
      else{
          a[0]=0;
          b[2]=0;
      }
      val = a[1] - b[2];
      if(val==0){
       System.out.println(sum);
      }
      else{
          sum-=2*Math.min(a[1],b[2]);
          System.out.println(sum);
      }
   }

 }
}


import java.util.*;

public class Main{

public static void main(String[] args) {

   Scanner scn=new Scanner(System.in);
   int t=scn.nextInt();
   while(t-->0){
       long sum=0;
       long[] a = new long[3];
       long[] b = new long[3];
       for(int i=0;i<3;i++){
           a[i]=scn.nextLong();
       }
       for(int i=0;i<3;i++){
           b[i]=scn.nextLong();
       }
       long val = a[2] - b[1];
       if(val>0){
           sum+=b[1]*2;
           a[2]-=b[1];
           b[1]=0;
       }
       else if(val<0){
           sum+=a[2]*2;
           b[1]-=a[2];
           a[2]=0;
       }
       else{
           sum+=a[2]*2;
           a[2]=0;
           b[1]=0;
       }

       long diff = a[0] + a[2];
       if(diff<b[2]){
           long val1 = b[2] - diff;
           sum-=2*val;
       }
       System.out.println(sum);

   }

 }
}


import java.util.*;

public class Main{

public static void main(String[] args) {

   Scanner scn=new Scanner(System.in);
   int t=scn.nextInt();
   while(t-->0){
       long sum=0;
       long[] a = new long[3];
       long[] b = new long[3];
       for(int i=0;i<3;i++){
           a[i]=scn.nextLong();
       }
       for(int i=0;i<3;i++){
           b[i]=scn.nextLong();
       }
       long val = a[2] - b[1];
       if(val>0){
           sum+=b[1]*2;
           a[2]-=b[1];
           b[1]=0;
       }
       else if(val<0){
           sum+=a[2]*2;
           b[1]-=a[2];
           a[2]=0;
       }
       else{
           sum+=a[2]*2;
           a[2]=0;
           b[1]=0;
       }
       System.out.println(sum);
   }

 }
}


import java.util.*;

public class Main{

public static void main(String[] args) {

   Scanner scn=new Scanner(System.in);
   int t=scn.nextInt();
   while(t-->0){
       long sum=0;
       long[] a = new long[3];
       long[] b = new long[3];
       for(int i=0;i<3;i++){
           a[i]=scn.nextLong();
       }
       for(int i=0;i<3;i++){
           b[i]=scn.nextLong();
       }
       long val = a[2] - b[1];
       if(val>0){
           sum+=b[1]*2;
           a[2]-=b[1];
           b[1]=0;
       }
       else if(val<0){
           sum+=a[2]*2;
           b[1]-=a[2];
           a[2]=0;
       }
       else{
           sum+=a[2]*2;
           a[2]=0;
           b[1]=0;
       }

       long diff = a[0] + a[2];
       if(diff<b[2]){
           long val1 = b[2] - diff;
           sum-=2*val1;
       }
       System.out.println(sum);

   }

 }
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class cf1 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static int inf = (int)(1e9) + 5;
    static long iinf = (long)(1e18);
    static double eps = (double)1e-4;
    static void solve()throws IOException {
        long z1 = f.nl(); long o1 = f.nl(); long t1 = f.nl();
        long z2 = f.nl(); long o2 = f.nl(); long t2 = f.nl();

        long ans = 0l;
        if (t2 <= z1) {
            ans += 2 * Math.min(t1 , o2);
        }
        else if (t2 <= t1 + o1) {
            t2 -= o1;
            t1 -= t2;
            ans += 2 * Math.min(t1 , o2);
        }
        else {
            t2 -= o1;
            t2 -= t1;
            ans -= 2 * Math.min(t2 , o1);
        }
        pn(ans);
    }
    public static void main(String[] args)throws NumberFormatException , IOException {
        init();
        boolean tc = true;
        int t = tc ? f.ni() : 1;
        while(t --> 0) solve();
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0l){if((b&1)==1l)res=((res%mod)*(a%mod))%mod;b>>=1l;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static int log2(int x){return (int)(Math.log(x)/Math.log(2));}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> res=new HashSet<Long>();for(Long i:ff)if(isPrime(i))res.add(i);return res;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> res=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))res.add(i);return res;}
    static int[] inpint(int n){int arr[]=new int[n+1];for(int i=1;i<=n;++i){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n+1];for(int i=1;i<=n;++i){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}//No. of integers less than equal to i in ub
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static int upperbound(int a[],int i){int lo=0,hi=a.length-1,mid=0;int count=0;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]<=i){count=mid+1;lo=mid+1;}else hi=mid-1;}return count;}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}//!Precompute fact in ncr()!
    static int nextPowerOf2(int n){int count=0;if(n>0&&(n&(n-1))==0)return n;while(n!=0){n>>=1;count += 1;}return 1<<count;}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class cf1 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static int inf = (int)(1e9) + 5;
    static long iinf = (long)(1e18);
    static double eps = (double)1e-4;
    static void solve()throws IOException {
        long z1 = f.nl(); long o1 = f.nl(); long t1 = f.nl();
        long z2 = f.nl(); long o2 = f.nl(); long t2 = f.nl();

        long ans = Math.min(t1 , o2);
        t1 -= ans;
        o2 -= ans;
        if (t2 > z1 + t1) ans -= Math.min(o2 , t2 - z1 - t1);
        pn(ans * 2);
    }
    public static void main(String[] args)throws NumberFormatException , IOException {
        init();
        boolean tc = true;
        int t = tc ? f.ni() : 1;
        while(t --> 0) solve();
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0l){if((b&1)==1l)res=((res%mod)*(a%mod))%mod;b>>=1l;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static int log2(int x){return (int)(Math.log(x)/Math.log(2));}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> res=new HashSet<Long>();for(Long i:ff)if(isPrime(i))res.add(i);return res;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> res=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))res.add(i);return res;}
    static int[] inpint(int n){int arr[]=new int[n+1];for(int i=1;i<=n;++i){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n+1];for(int i=1;i<=n;++i){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}//No. of integers less than equal to i in ub
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static int upperbound(int a[],int i){int lo=0,hi=a.length-1,mid=0;int count=0;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]<=i){count=mid+1;lo=mid+1;}else hi=mid-1;}return count;}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}//!Precompute fact in ncr()!
    static int nextPowerOf2(int n){int count=0;if(n>0&&(n&(n-1))==0)return n;while(n!=0){n>>=1;count += 1;}return 1<<count;}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class cf1 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static int inf = (int)(1e9) + 5;
    static long iinf = (long)(1e18);
    static double eps = (double)1e-4;
    static void solve()throws IOException {
        long z1 = f.nl(); long o1 = f.nl(); long t1 = f.nl();
        long z2 = f.nl(); long o2 = f.nl(); long t2 = f.nl();

        long ans = Math.min(t1 , o2);
        t1 -= ans;
        o2 -= ans;
        if (t2 > z1 + t1) ans -= Math.min(o1 , t2 - z1 - t1);
        pn(ans * 2);
    }
    public static void main(String[] args)throws NumberFormatException , IOException {
        init();
        boolean tc = true;
        int t = tc ? f.ni() : 1;
        while(t --> 0) solve();
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0l){if((b&1)==1l)res=((res%mod)*(a%mod))%mod;b>>=1l;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static int log2(int x){return (int)(Math.log(x)/Math.log(2));}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> res=new HashSet<Long>();for(Long i:ff)if(isPrime(i))res.add(i);return res;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> res=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))res.add(i);return res;}
    static int[] inpint(int n){int arr[]=new int[n+1];for(int i=1;i<=n;++i){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n+1];for(int i=1;i<=n;++i){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}//No. of integers less than equal to i in ub
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static int upperbound(int a[],int i){int lo=0,hi=a.length-1,mid=0;int count=0;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]<=i){count=mid+1;lo=mid+1;}else hi=mid-1;}return count;}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}//!Precompute fact in ncr()!
    static int nextPowerOf2(int n){int count=0;if(n>0&&(n&(n-1))==0)return n;while(n!=0){n>>=1;count += 1;}return 1<<count;}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class cf1 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static int inf = (int)(1e9) + 5;
    static long iinf = (long)(1e18);
    static double eps = (double)1e-4;
    static void solve()throws IOException {
        long z1 = f.nl(); long o1 = f.nl(); long t1 = f.nl();
        long z2 = f.nl(); long o2 = f.nl(); long t2 = f.nl();

        long ans = 0l;
        if (t2 <= z1) {
            ans += 2 * Math.min(t1 , o2);
        }
        else if (t2 <= t1 + o1) {
            t2 -= o1;
            t1 -= t2;
            ans += 2 * Math.min(t1 , o2);
        }
        else {
            t2 -= o1;
            t1 -= t2;
            ans += 2 * Math.min(t1 , o2);
        }
        pn(ans);
    }
    public static void main(String[] args)throws NumberFormatException , IOException {
        init();
        boolean tc = true;
        int t = tc ? f.ni() : 1;
        while(t --> 0) solve();
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0l){if((b&1)==1l)res=((res%mod)*(a%mod))%mod;b>>=1l;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static int log2(int x){return (int)(Math.log(x)/Math.log(2));}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> res=new HashSet<Long>();for(Long i:ff)if(isPrime(i))res.add(i);return res;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> res=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))res.add(i);return res;}
    static int[] inpint(int n){int arr[]=new int[n+1];for(int i=1;i<=n;++i){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n+1];for(int i=1;i<=n;++i){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}//No. of integers less than equal to i in ub
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static int upperbound(int a[],int i){int lo=0,hi=a.length-1,mid=0;int count=0;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]<=i){count=mid+1;lo=mid+1;}else hi=mid-1;}return count;}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}//!Precompute fact in ncr()!
    static int nextPowerOf2(int n){int count=0;if(n>0&&(n&(n-1))==0)return n;while(n!=0){n>>=1;count += 1;}return 1<<count;}
}


import java.util.*;
public class Prb2{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            long x1 = sc.nextLong();
            long y1 = sc.nextLong();
            long z1 = sc.nextLong();

            long x2 = sc.nextLong();
            long y2 = sc.nextLong();
            long z2 = sc.nextLong();

            long ans =  (long)2* min(z1, y2);
            z1 -=  min(z1, y2);
            y2 -=  min(z1, y2);

            if( z2 > 0 && z1 > 0 ){
                z1 -=  min(z1,z2);
                z2 -=  min(z1,z2);

            }

            if(  z2 > 0 && x1 > 0 ){
                z2 -=  min(z2, x1);
                x1 -=  min(z2, x1);
            }

            ans -= (long)2* min(z2, y1);

            System.out.println(ans);

        }

    }
    static long min(long a, long b){
        if( a > b)
            return b;
        return a;
    }
 }


import java.util.*;
public class Prb2{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            long x1 = sc.nextLong();
            long y1 = sc.nextLong();
            long z1 = sc.nextLong();

            long x2 = sc.nextLong();
            long y2 = sc.nextLong();
            long z2 = sc.nextLong();

            long ans =  2*Math.min(z1, y2);
            z1 -= Math.min(z1, y2);
            y2 -= Math.min(z1, y2);

            if( z2 > 0 && z1 > 0 ){
                z1 -= Math.min(z1,z2);
                z2 -= Math.min(z1,z2);

            }

            if(  z2 > 0 && x1 > 0 ){
                z2 -= Math.min(z2, x1);
                x1 -= Math.min(z2, x1);
            }

            ans -= 2*Math.min(z2, y1);

            System.out.println(ans);

        }

    }
}


import java.util.*;
public class Prb2{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int tt = sc.nextInt();
        while(tt-->0){
            long x1 = sc.nextLong();
            long y1 = sc.nextLong();
            long z1 = sc.nextLong();

            long x2 = sc.nextLong();
            long y2 = sc.nextLong();
            long z2 = sc.nextLong();

            long ans =  (long)2* min(z1, y2);
            long t = min(z1, y2);
            z1 -=  t;
            y2 -=  t;

             t = min(z1,z2);
            if( z2 > 0 && z1 > 0 ){
                z1 -=  t;
                z2 -=  t;

            }

            t = min(z2, x1);
            if(  z2 > 0 && x1 > 0 ){
                z2 -=  t;
                x1 -=  t;
            }

            ans -= (long)2* min(z2, y1);

            System.out.println(ans);

        }

    }
    static long min(long a, long b){
        if( a > b)
            return b;
        return a;
    }
 }


import java.util.*;
public class Prb2{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int z1 = sc.nextInt();

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

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

            if( z2 > 0 && z1 > 0 ){
                z1 -= Math.min(z1,z2);
                z2 -= Math.min(z1,z2);

            }

            if(  z2 > 0 && x1 > 0 ){
                z2 -= Math.min(z2, x1);
                x1 -= Math.min(z2, x1);
            }

            ans -= 2*Math.min(z2, y1);

            System.out.println(ans);

        }

    }
 }


import java.util.*;
public class Prb2{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int z1 = sc.nextInt();

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

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

            if( z2 > 0 && z1 > 0 ){
                z1 -= Math.min(z1,z2);
                z2 -= Math.min(z1,z2);

            }

            if(  z2 > 0 && x1 > 0 ){
                z2 -= Math.min(z2, x1);
                x1 -= Math.min(z2, x1);
            }

            ans -= 2*Math.min(z2, y1);

            System.out.println(ans);

        }

    }
    static long min(long a, long b)
}


import java.util.*;
public class Prb2{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            long x1 = sc.nextLong();
            long y1 = sc.nextLong();
            long z1 = sc.nextLong();

            long x2 = sc.nextLong();
            long y2 = sc.nextLong();
            long z2 = sc.nextLong();

            long ans =  2*Math.min(z1, y2);
            z1 -= Math.min(z1, y2);
            y2 -= Math.min(z1, y2);

            if( z1 >= z2 ){
                z1 -= Math.min(z1,z2);
                z2 -= Math.min(z1,z2);

            }

            if( x1 > z2 &&  x1 > 0){
                z2 -= Math.min(z2, x1);
                x1 -= Math.min(z2, x1);
            }

            System.out.println(ans);

        }

    }
}


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

public class Prb25 {

    static FastReader sc = new FastReader();

    public static void main(String[] args) {
        int t = sc.nextInt();
        while(t-- != 0){

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

            long sum = 0;

           if(y2 > 0 && z1 > 0){
            if(z1 < y2){
                sum += 2*z1;
                y2 -= z1;
                z1 = 0;
            }
            else{
                sum += 2*(y2-z1);
                z1 -= y2;
                y2 = 0;
            }
           }

           if(z1 > 0 && z2 > 0){
            if(z1 > 0){
                int temp = z2;
                z2 -= z1;
                z1 -= temp;
            }
           }

           if(z2 > 0 && x1 > 0){
            if( z2 > 0){
                int temp = z2;
                z2 -= x1;
                x1 -= temp;
            }
           }

          if(z2 > 0){
              sum -= 2*z2;
          }

          System.out.println(sum);

        }
    }

    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 Prb25 {

    static FastReader sc = new FastReader();

    public static void main(String[] args) {
        int t = sc.nextInt();
        while(t-- != 0){

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

            long sum = 0;

           if(y2 > 0 && z1 > 0){
            if(z1 < y2){
                sum += 2*z1;
                y2 -= z1;
                z1 = 0;
            }
            else{
                sum += 2*(y2-z1);
                z1 -= y2;
                y2 = 0;
            }
           }

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

          if( z2 > 0){
              int temp = z2;
              z2 -= x1;
              x1 -= z2;

          }

          if(z2 > 0){
              sum -= 2*z2;
          }

          System.out.println(sum);

        }
    }

    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 Prb25 {

    static FastReader sc = new FastReader();

    public static void main(String[] args) {
        int t = sc.nextInt();
        while(t-- != 0){

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

            long sum = 0;

           if(y2 > 0 && z1 > 0){
            if(z1 <= y2){
                sum += 2*z1;
                y2 -= z1;
                z1 = 0;
            }
            else{
                sum += 2*(y2);
                z1 -= y2;
                y2 = 0;
            }
           }

           if(z1 > 0 && z2 > 0){
            if(z1 > 0){
                int temp = z2;
                z2 -= z1;
                z1 -= temp;
            }
           }

           if(z2 > 0 && x1 > 0){
            if( z2 > 0){
                int temp = z2;
                z2 -= x1;
                x1 -= temp;
            }
           }

          if(z2 > 0){
              sum -= 2*z2;
          }

          System.out.println(sum);

        }
    }

    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.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;

public class CodeForce {

	static boolean flag = false;

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

		 int t=Integer.parseInt(br.readLine()); while(t-->0) {
String[] sr=br.readLine().split(" ");
int x1=Integer.parseInt(sr[0]);
int y1=Integer.parseInt(sr[1]);
int z1=Integer.parseInt(sr[2]);
 sr=br.readLine().split(" ");
int x2=Integer.parseInt(sr[0]);
int y2=Integer.parseInt(sr[1]);
int z2=Integer.parseInt(sr[2]);
int sum=0;
sum=Math.min(z1, x2)*2;
int temp=Math.min(z1, x2);
z1-=temp;
x2-=temp;
temp=Math.min(z2, z1);
	z1-=temp;
	z2-=temp;

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

	}

}}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;

public class CodeForce {

	static boolean flag = false;

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

		 int t=Integer.parseInt(br.readLine()); while(t-->0) {
String[] sr=br.readLine().split(" ");
int x1=Integer.parseInt(sr[0]);
int y1=Integer.parseInt(sr[1]);
int z1=Integer.parseInt(sr[2]);
 sr=br.readLine().split(" ");
int x2=Integer.parseInt(sr[0]);
int y2=Integer.parseInt(sr[1]);
int z2=Integer.parseInt(sr[2]);
int sum=0;

sum=Math.min(z1, y2)*2;
int temp=Math.min(z1, y2);
z1-=temp;
y2-=temp;
temp=Math.min(z2, z1);
	z1-=temp;
	z2-=temp;

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

	}

}}

sum=Math.min(z1, y2)*2;
int temp=Math.min(z1, y2);
z1-=temp;
y2-=temp;
temp=Math.min(z2, z1);
	z1-=temp;
	z2-=temp;

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

	}

}}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;

public class CodeForce {

	static boolean flag = false;

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

		 int t=Integer.parseInt(br.readLine()); while(t-->0) {
String[] sr=br.readLine().split(" ");
int x1=Integer.parseInt(sr[0]);
int y1=Integer.parseInt(sr[1]);
int z1=Integer.parseInt(sr[2]);
 sr=br.readLine().split(" ");
int x2=Integer.parseInt(sr[0]);
int y2=Integer.parseInt(sr[1]);
int z2=Integer.parseInt(sr[2]);
int sum=0;

sum=Math.min(z1, y2)*2;
int temp=Math.min(z1, y2);
z1-=temp;
y2-=temp;
temp=Math.min(z2, z1);
	z1-=temp;
	z2-=temp;

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

	}

}}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static HashSet<Pair> hash;
    static ArrayList<Integer> list;
    static long ceildiv(long x, long y) { return (x + y - 1) / y; }
    static int mod(long x, int m) { return (int) ((x % m + m) % m); }
    public static long gcd(long x, long y) {return y == 0 ? x : gcd(y, x % y);}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            int[] a=sc.nextArr(3), b=sc.nextArr(3);
            long ans=0;
            int min=Math.min(a[0], b[2]);
            b[2]-=min;
            a[0]-=min;
            min=Math.min(a[1], b[0]);
            b[0]-=min;
            a[1]-=min;
            for(int i=2, j=2; i>=0 && j>=0; ){
                if(a[i]>b[j]){
                    int diff=i-j;
                    diff=(diff!=0?diff/Math.abs(diff):0);
                    ans+=(i*j)*1l*b[j]*diff;
                    a[i]-=b[j--];
                }else if(a[i]<b[j]){
                    int diff=i-j;
                    diff=(diff!=0?diff/Math.abs(diff):0);
                    ans+=(i*j)*1l*a[i]*diff;
                    a[j]-=a[i--];
                }else{
                    int diff=i-j;
                    diff=(diff!=0?diff/Math.abs(diff):0);
                    ans+=(i*j)*1l*a[i]*diff;
                    i--; j--;
                }
            }
            pw.println(ans);
        }
        pw.close();
    }
    static int getidx(int i, TreeSet<Integer> tree){
        Integer idx=tree.ceiling(i);
        return idx==null?tree.first():idx;
    }
    static int getidx2(int i, TreeSet<Integer> tree){
        Integer idx=tree.floor(i);
        return idx==null?tree.last():idx;
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]);
        pw.println();
    }
    static void printArr(ArrayList list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i) + " ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

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

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

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

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        long x;
        long y;
        public Pair(long x, long y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (int)(this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            return (int)(this.x-p.x);
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
        public Pair multiply(int x){
            return new Pair(x*this.x, x*this.y);
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static HashSet<Pair> hash;
    static ArrayList<Integer> list;
    static long ceildiv(long x, long y) { return (x + y - 1) / y; }
    static int mod(long x, int m) { return (int) ((x % m + m) % m); }
    public static long gcd(long x, long y) {return y == 0 ? x : gcd(y, x % y);}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            int[] a=sc.nextArr(3), b=sc.nextArr(3);
            long ans=0;
            int min=Math.min(a[0], b[2]);
            b[2]-=min;
            a[0]-=min;
            min=Math.min(a[1], b[0]);
            b[0]-=min;
            a[1]-=min;
            pw.println(Math.min(a[2], b[1])*2l+ Math.min(a[1], b[2])*-2l);
        }
        pw.close();
    }
    static int getidx(int i, TreeSet<Integer> tree){
        Integer idx=tree.ceiling(i);
        return idx==null?tree.first():idx;
    }
    static int getidx2(int i, TreeSet<Integer> tree){
        Integer idx=tree.floor(i);
        return idx==null?tree.last():idx;
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]);
        pw.println();
    }
    static void printArr(ArrayList list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i) + " ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

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

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

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

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        long x;
        long y;
        public Pair(long x, long y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (int)(this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            return (int)(this.x-p.x);
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
        public Pair multiply(int x){
            return new Pair(x*this.x, x*this.y);
        }
    }
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static HashSet<Pair> hash;
    static ArrayList<Integer> list;
    static long ceildiv(long x, long y) { return (x + y - 1) / y; }
    static int mod(long x, int m) { return (int) ((x % m + m) % m); }
    public static long gcd(long x, long y) {return y == 0 ? x : gcd(y, x % y);}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0){
            int[] a=sc.nextArr(3), b=sc.nextArr(3);
            long ans=0;
            int min=Math.min(a[0], b[2]);
            b[2]-=min;
            a[0]-=min;
            for(int i=2, j=2; i>=0 && j>=0; ){
                if(a[i]>b[j]){
                    int diff=i-j;
                    diff=(diff!=0?diff/Math.abs(diff):0);
                    ans+=(i*j)*1l*b[j]*diff;
                    a[i]-=b[j--];
                }else if(a[i]<b[j]){
                    int diff=i-j;
                    diff=(diff!=0?diff/Math.abs(diff):0);
                    ans+=(i*j)*1l*a[i]*diff;
                    a[j]-=a[i--];
                }else{
                    int diff=i-j;
                    diff=(diff!=0?diff/Math.abs(diff):0);
                    ans+=(i*j)*1l*a[i]*diff;
                    i--; j--;
                }
            }
            pw.println(ans);
        }
        pw.close();
    }
    static int getidx(int i, TreeSet<Integer> tree){
        Integer idx=tree.ceiling(i);
        return idx==null?tree.first():idx;
    }
    static int getidx2(int i, TreeSet<Integer> tree){
        Integer idx=tree.floor(i);
        return idx==null?tree.last():idx;
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]);
        pw.println();
    }
    static void printArr(ArrayList list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i) + " ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

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

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

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

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        long x;
        long y;
        public Pair(long x, long y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (int)(this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            return (int)(this.x-p.x);
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
        public Pair multiply(int x){
            return new Pair(x*this.x, x*this.y);
        }
    }
}


//package Codeforces_contest;

/**
 *
 * @author Abhishek
 */
import java.io.*;
import java.util.*;
public class CF665Div2 {

    InputStream obj;
    PrintWriter out;
    String check = "";

    //Solution !!
    void solution() {
        int tt = inti();
        for(int t = 0; t < tt; t++) {
            int x1 = inti(), y1 = inti(), z1 = inti();
            int x2 = inti(), y2 = inti(), z2 = inti();

            long ans = 0;

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

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

            out.println(ans);
        }
    }

    //------->ends !!
    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new CF665Div2().ace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (StackOverflowError e) {
                    System.out.println("RTE");
                }
            }
        }, "1", 1 << 26).start();
    }

    void ace() throws IOException {
        out = new PrintWriter(System.out);
        obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
//        obj=check.isEmpty() ? new FileInputStream("location of file") : new ByteArrayInputStream(check.getBytes());
//        long t1=System.currentTimeMillis();
        solution();
//        long t2=System.currentTimeMillis();
//        out.println(t2-t1);
        out.flush();
        out.close();
    }
    byte inbuffer[] = new byte[1024];
    int lenbuffer = 0, ptrbuffer = 0;

    int readByte() {
        if (lenbuffer == -1) {
            throw new InputMismatchException();
        }
        if (ptrbuffer >= lenbuffer) {
            ptrbuffer = 0;
            try {
                lenbuffer = obj.read(inbuffer);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        if (lenbuffer <= 0) {
            return -1;
        }
        return inbuffer[ptrbuffer++];
    }

    boolean isSpaceChar(int c) {
        return (!(c >= 33 && c <= 126));
    }

    String stri() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
        {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b));
        return b;
    }

    int inti() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    int[][] ar2D(int n, int m) {
        int ark[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ark[i][j] = inti();
            }
        }
        return ark;
    }

    long loni() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    float fl() {
        return Float.parseFloat(stri());
    }

    double dou() {
        return Double.parseDouble(stri());
    }

    char chi() {
        return (char) skip();
    }

    int[] arri(int n) {
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = inti();
        }
        return a;
    }

    long[] arrl(int n) {
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = loni();
        }
        return a;
    }

    String[] stra(int n) {
        String a[] = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = stri();
        }
        return a;
    }

    private static void pa(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
//    uwi mod pow function

    public static long pow(long a, long n, long mod) {
//		a %= mod;
        long ret = 1;
        int x = 63 - Long.numberOfLeadingZeros(n);
        for (; x >= 0; x--) {
            ret = ret * ret % mod;
            if (n << 63 - x < 0) {
                ret = ret * a % mod;
            }
        }
        return ret;
    }

    int gcd(int a, int b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    long lcm(int a, int b) {
        return a * (b / gcd(a, b));
    }
}


//package Codeforces_contest;

/**
 *
 * @author Abhishek
 */
import java.io.*;
import java.util.*;
public class CF665Div2 {

    InputStream obj;
    PrintWriter out;
    String check = "";

    //Solution !!
    void solution() {
        int tt = inti();
        for(int t = 0; t < tt; t++) {
            int x1 = inti(), y1 = inti(), z1 = inti();
            int x2 = inti(), y2 = inti(), z2 = inti();

            long ans = 0;

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

            int a = x1 + z1;
            if(a < z2) {
                ans -= 2 * Math.max(z2 - Math.min(a, y1), 0);
            }

            out.println(ans);
        }
    }

    //------->ends !!
    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new CF665Div2().ace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (StackOverflowError e) {
                    System.out.println("RTE");
                }
            }
        }, "1", 1 << 26).start();
    }

    void ace() throws IOException {
        out = new PrintWriter(System.out);
        obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
//        obj=check.isEmpty() ? new FileInputStream("location of file") : new ByteArrayInputStream(check.getBytes());
//        long t1=System.currentTimeMillis();
        solution();
//        long t2=System.currentTimeMillis();
//        out.println(t2-t1);
        out.flush();
        out.close();
    }
    byte inbuffer[] = new byte[1024];
    int lenbuffer = 0, ptrbuffer = 0;

    int readByte() {
        if (lenbuffer == -1) {
            throw new InputMismatchException();
        }
        if (ptrbuffer >= lenbuffer) {
            ptrbuffer = 0;
            try {
                lenbuffer = obj.read(inbuffer);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        if (lenbuffer <= 0) {
            return -1;
        }
        return inbuffer[ptrbuffer++];
    }

    boolean isSpaceChar(int c) {
        return (!(c >= 33 && c <= 126));
    }

    String stri() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
        {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b));
        return b;
    }

    int inti() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    int[][] ar2D(int n, int m) {
        int ark[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ark[i][j] = inti();
            }
        }
        return ark;
    }

    long loni() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    float fl() {
        return Float.parseFloat(stri());
    }

    double dou() {
        return Double.parseDouble(stri());
    }

    char chi() {
        return (char) skip();
    }

    int[] arri(int n) {
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = inti();
        }
        return a;
    }

    long[] arrl(int n) {
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = loni();
        }
        return a;
    }

    String[] stra(int n) {
        String a[] = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = stri();
        }
        return a;
    }

    private static void pa(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
//    uwi mod pow function

    public static long pow(long a, long n, long mod) {
//		a %= mod;
        long ret = 1;
        int x = 63 - Long.numberOfLeadingZeros(n);
        for (; x >= 0; x--) {
            ret = ret * ret % mod;
            if (n << 63 - x < 0) {
                ret = ret * a % mod;
            }
        }
        return ret;
    }

    int gcd(int a, int b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    long lcm(int a, int b) {
        return a * (b / gcd(a, b));
    }
}


//package Codeforces_contest;

/**
 *
 * @author Abhishek
 */
import java.io.*;
import java.util.*;
public class CF665Div2 {

    InputStream obj;
    PrintWriter out;
    String check = "";

    //Solution !!
    void solution() {
        int tt = inti();
        for(int t = 0; t < tt; t++) {
            int x1 = inti(), y1 = inti(), z1 = inti();
            int x2 = inti(), y2 = inti(), z2 = inti();

            long ans = 0;

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

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

            out.println(ans);
        }
    }

    //------->ends !!
    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new CF665Div2().ace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (StackOverflowError e) {
                    System.out.println("RTE");
                }
            }
        }, "1", 1 << 26).start();
    }

    void ace() throws IOException {
        out = new PrintWriter(System.out);
        obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
//        obj=check.isEmpty() ? new FileInputStream("location of file") : new ByteArrayInputStream(check.getBytes());
//        long t1=System.currentTimeMillis();
        solution();
//        long t2=System.currentTimeMillis();
//        out.println(t2-t1);
        out.flush();
        out.close();
    }
    byte inbuffer[] = new byte[1024];
    int lenbuffer = 0, ptrbuffer = 0;

    int readByte() {
        if (lenbuffer == -1) {
            throw new InputMismatchException();
        }
        if (ptrbuffer >= lenbuffer) {
            ptrbuffer = 0;
            try {
                lenbuffer = obj.read(inbuffer);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        if (lenbuffer <= 0) {
            return -1;
        }
        return inbuffer[ptrbuffer++];
    }

    boolean isSpaceChar(int c) {
        return (!(c >= 33 && c <= 126));
    }

    String stri() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
        {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b));
        return b;
    }

    int inti() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    int[][] ar2D(int n, int m) {
        int ark[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ark[i][j] = inti();
            }
        }
        return ark;
    }

    long loni() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    float fl() {
        return Float.parseFloat(stri());
    }

    double dou() {
        return Double.parseDouble(stri());
    }

    char chi() {
        return (char) skip();
    }

    int[] arri(int n) {
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = inti();
        }
        return a;
    }

    long[] arrl(int n) {
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = loni();
        }
        return a;
    }

    String[] stra(int n) {
        String a[] = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = stri();
        }
        return a;
    }

    private static void pa(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
//    uwi mod pow function

    public static long pow(long a, long n, long mod) {
//		a %= mod;
        long ret = 1;
        int x = 63 - Long.numberOfLeadingZeros(n);
        for (; x >= 0; x--) {
            ret = ret * ret % mod;
            if (n << 63 - x < 0) {
                ret = ret * a % mod;
            }
        }
        return ret;
    }

    int gcd(int a, int b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    long lcm(int a, int b) {
        return a * (b / gcd(a, b));
    }
}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class ForLooops {
	 static class FastReader
	    {
	        BufferedReader br;
	        StringTokenizer st;

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

	        String next()
	        {
	            while (st == null || !st.hasMoreTokens())
	            {
	                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;
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			}
	    }

	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();
		int t = s.nextInt();
		while(t-->0) {
			int x1 = s.nextInt();
			int y1 = s.nextInt();
			int z1 = s.nextInt();
			int x2 = s.nextInt();
			int y2 = s.nextInt();
			int z2 = s.nextInt();
			System.out.println(Math.min(z1, y2)*2);

		}

	}

}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class ForLooops {
	 static class FastReader
	    {
	        BufferedReader br;
	        StringTokenizer st;

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

	        String next()
	        {
	            while (st == null || !st.hasMoreTokens())
	            {
	                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;
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			}
	    }

	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();
		int t = s.nextInt();
		while(t-->0) {
			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 m =Math.min(x1, z2);
			z2-=m;
			x1-=m;
			m = Math.min(y1, x2);
			y1-=m;
			x2-=m;

			m = Math.min(z1, y2);
			z1-=m;
			y2-=m;
			int sum = m*2;
			sum-= Math.min(y1, z2)*2;

			System.out.println(sum);

		}

	}

}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class ForLooops {
	 static class FastReader
	    {
	        BufferedReader br;
	        StringTokenizer st;

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

	        String next()
	        {
	            while (st == null || !st.hasMoreTokens())
	            {
	                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;
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			}
	    }

	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();
		int t = s.nextInt();
		while(t-->0) {
			int x1 = s.nextInt();
			int y1 = s.nextInt();
			int z1 = s.nextInt();
			int x2 = s.nextInt();
			int y2 = s.nextInt();
			int z2 = s.nextInt();
			long p = Math.min(z1, y2)*2;

			System.out.println(Math.max(p, Math.min(z2, y1)*2));

		}

	}

}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class ForLooops {
	 static class FastReader
	    {
	        BufferedReader br;
	        StringTokenizer st;

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

	        String next()
	        {
	            while (st == null || !st.hasMoreTokens())
	            {
	                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;
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			}
	    }

	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();
		int t = s.nextInt();
		while(t-->0) {
			int x1 = s.nextInt();
			int y1 = s.nextInt();
			int z1 = s.nextInt();
			int x2 = s.nextInt();
			int y2 = s.nextInt();
			int z2 = s.nextInt();
			long p = Math.min(z1, y2)*2;

			System.out.println(Math.max(p, -Math.min(z2, y1)*2));

		}

	}

}


//package codeforces.D1401;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author muhossain
 * @since 2020-08-14
 */

public class B {

    public static void main(String[] args) {
        FastReader fs = new FastReader();

        int testCases = fs.nextInt();
        StringBuilder output = new StringBuilder();

        for (int t = 0; t < testCases; t++) {

            int x1 = fs.nextInt(); // 0
            int y1 = fs.nextInt(); // 1
            int z1 = fs.nextInt(); // 2

            int x2 = fs.nextInt(); // 0
            int y2 = fs.nextInt(); // 1
            int z2 = fs.nextInt(); // 2

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

            if (x1 > 0 && x2 > 0) {
                if (x1 >= x2) {
                    x1 -= x2;
                    x2 = 0;
                } else {
                    x1 = 0;
                    x2 -= x1;
                }
            }

            if (x1 > 0 && y2 > 0) {
                if (x1 >= y2) {
                    x1 -= y2;
                    y2 = 0;
                } else {
                    x1 = 0;
                    y2 -= x1;
                }

            }

            if (y1 > 0 && x2 > 0) {
                if (y1 >= x2) {
                    y1 -= x2;
                    x2 = 0;
                } else {
                    y1 = 0;
                    x2 -= y1;
                }
            }

            if (y1 > 0 && y2 > 0) {
                if (y1 >= y2) {
                    y1 -= y2;
                    y2 = 0;
                } else {
                    y1 = 0;
                    y2 -= y1;
                }
            }

            int total = 0;

            if (y1 > 0 && z2 > 0) {
                if (y1 >= z2) {
                    total -= (z2 * 2);

                    y1 -= z2;
                    z2 = 0;

                } else {
                    total -= (y1 * 2);

                    y1 = 0;
                    z2 -= y1;
                }
            }

            if (z1 > 0 && y2 > 0) {
                if (z1 >= y2) {
                    total += (y2 * 2);

                    z1 -= y2;
                    y2 = 0;
                } else {
                    total += (z1 * 2);

                    y2 -= z1;
                    z1 = 0;
                }
            }

            output.append(total).append("\n");
        }

        System.out.print(output);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        public static FastReader getFileReader(String fileName) throws FileNotFoundException {
            return new FastReader(new InputStreamReader(new FileInputStream(new File(fileName))));
        }

        public static FastReader getDefaultReader() throws FileNotFoundException {
            return new FastReader();
        }

        public FastReader(InputStreamReader inputStreamReader) {
            br = new BufferedReader(inputStreamReader);
        }

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


//package codeforces.D1401;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author muhossain
 * @since 2020-08-14
 */

public class B {

    public static void main(String[] args) {
        FastReader fs = new FastReader();

        int testCases = fs.nextInt();
        StringBuilder output = new StringBuilder();

        for (int t = 0; t < testCases; t++) {

            int x1 = fs.nextInt(); // 0
            int y1 = fs.nextInt(); // 1
            int z1 = fs.nextInt(); // 2

            int x2 = fs.nextInt(); // 0
            int y2 = fs.nextInt(); // 1
            int z2 = fs.nextInt(); // 2

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

            if (x1 > 0 && x2 > 0) {
                if (x1 >= x2) {
                    x1 -= x2;
                    x2 = 0;
                } else {
                    x1 = 0;
                    x2 -= x1;
                }
            }

            if (x1 > 0 && y2 > 0) {
                if (x1 >= y2) {
                    x1 -= y2;
                    y2 = 0;
                } else {
                    x1 = 0;
                    y2 -= x1;
                }

            }

            if (y1 > 0 && x2 > 0) {
                if (y1 >= x2) {
                    y1 -= x2;
                    x2 = 0;
                } else {
                    y1 = 0;
                    x2 -= y1;
                }
            }

            int total = 0;

            if (y1 > 0 && z2 > 0) {
                if (y1 >= z2) {
                    total -= (z2 * 2);

                    y1 -= z2;
                    z2 = 0;

                } else {
                    total -= (y1 * 2);

                    y1 = 0;
                    z2 -= y1;
                }
            }

            if (y1 > 0 && y2 > 0) {
                if (y1 >= y2) {
                    y1 -= y2;
                    y2 = 0;
                } else {
                    y1 = 0;
                    y2 -= y1;
                }
            }

            if (z1 > 0 && y2 > 0) {
                if (z1 >= y2) {
                    total += (y2 * 2);

                    z1 -= y2;
                    y2 = 0;
                } else {
                    total += (z1 * 2);

                    y2 -= z1;
                    z1 = 0;
                }
            }

            if (t == 2140) {
                output.append(x1 + "" + y1 + "" + z1);
                output.append(x2 + "" + y2 + "" + z2).append("\n");
            } else {
                output.append(total).append("\n");
            }
        }

        System.out.print(output);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        public static FastReader getFileReader(String fileName) throws FileNotFoundException {
            return new FastReader(new InputStreamReader(new FileInputStream(new File(fileName))));
        }

        public static FastReader getDefaultReader() throws FileNotFoundException {
            return new FastReader();
        }

        public FastReader(InputStreamReader inputStreamReader) {
            br = new BufferedReader(inputStreamReader);
        }

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


//package codeforces.D1401;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author muhossain
 * @since 2020-08-14
 */

public class B {

    public static void main(String[] args) {
        FastReader fs = new FastReader();

        int testCases = fs.nextInt();
        StringBuilder output = new StringBuilder();

        for (int t = 0; t < testCases; t++) {

            int x1 = fs.nextInt(); // 0
            int y1 = fs.nextInt(); // 1
            int z1 = fs.nextInt(); // 2

            int x2 = fs.nextInt(); // 0
            int y2 = fs.nextInt(); // 1
            int z2 = fs.nextInt(); // 2

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

            if (x1 > 0) {
                if (x1 >= x2) {
                    x1 -= x2;
                    x2 = 0;
                } else {
                    x1 = 0;
                    x2 -= x1;
                }
            }

            if (x1 > 0) {
                if (x1 >= y2) {
                    x1 -= y2;
                    y2 = 0;
                } else {
                    x1 = 0;
                    y2 -= x1;
                }

            }

            if (y1 > 0) {
                if (y1 >= x2) {
                    y1 -= x2;
                    x2 = 0;
                } else {
                    y1 = 0;
                    x2 -= y1;
                }
            }

            if (y1 > 0) {
                if (y1 >= y2) {
                    y1 -= y2;
                    y2 = 0;
                } else {
                    y1 = 0;
                    y2 -= y1;
                }
            }

            int total = 0;

            if (y1 > 0) {
                if (y1 >= z2) {
                    total -= (z2 * 2);

                    y1 -= z2;
                    z2 = 0;

                } else {
                    total -= (y1 * 2);

                    y1 = 0;
                    z2 -= y1;
                }
            }

            if (z1 > 0) {
                if (z1 >= y2) {
                    total += (y2 * 2);

                    z1 -= y2;
                    y2 = 0;
                } else {
                    total += (z1 * 2);

                    y2 -= z1;
                    z1 = 0;
                }
            }

            output.append(total).append("\n");
        }

        System.out.print(output);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        public static FastReader getFileReader(String fileName) throws FileNotFoundException {
            return new FastReader(new InputStreamReader(new FileInputStream(new File(fileName))));
        }

        public static FastReader getDefaultReader() throws FileNotFoundException {
            return new FastReader();
        }

        public FastReader(InputStreamReader inputStreamReader) {
            br = new BufferedReader(inputStreamReader);
        }

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