You are given two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Each element of both sequences is either 0, 1 or 2. The number of elements 0, 1, 2 in the sequence a is x_1, y_1, z_1 respectively, and the number of elements 0, 1, 2 in the sequence b is x_2, y_2, z_2 respectively.

You can rearrange the elements in both sequences a and b however you like. After that, let's define a sequence c as follows:

c_i = \begin{cases} a_i b_i & \mbox{if }a_i > b_i \\\ 0 & \mbox{if }a_i = b_i \\\ -a_i b_i & \mbox{if }a_i < b_i \end{cases}

You'd like to make ∑_{i=1}^n c_i (the sum of all elements of the sequence c) as large as possible. What is the maximum possible sum?

Input

The first line contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases.

Each test case consists of two lines. The first line of each test case contains three integers x_1, y_1, z_1 (0 ≤ x_1, y_1, z_1 ≤ 10^8) — the number of 0-s, 1-s and 2-s in the sequence a.

The second line of each test case also contains three integers x_2, y_2, z_2 (0 ≤ x_2, y_2, z_2 ≤ 10^8; x_1 + y_1 + z_1 = x_2 + y_2 + z_2 > 0) — the number of 0-s, 1-s and 2-s in the sequence b.

Output

For each test case, print the maximum possible sum of the sequence c.

Example

Input


3
2 3 2
3 3 1
4 0 1
2 3 0
0 0 1
0 0 1


Output


4
2
0

Note

In the first sample, one of the optimal solutions is:

a = \{2, 0, 1, 1, 0, 2, 1\}

b = \{1, 0, 1, 0, 2, 1, 0\}

c = \{2, 0, 0, 0, 0, 2, 0\}

In the second sample, one of the optimal solutions is:

a = \{0, 2, 0, 0, 0\}

b = \{1, 1, 0, 1, 0\}

c = \{0, 2, 0, 0, 0\}

In the third sample, the only possible solution is:

a = \{2\}

b = \{2\}

c = \{0\}
import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
public class Main {
	
	public static long GCD(long i, long j){
	if (i==0){
		return j;
	}
	return GCD(j%i,i);
	}
	public static long LCM(long i, long j){
		return(i*j)/GCD(i,j);
	}

	public static void main(String[] args) throws Exception {
	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 sum=0;

	sum+=2*Math.min(z1, y2);
	z1=z1-Math.min(z1, y2);
	z2=z2-z1;
	z2=z2-Math.min(x1, z2);
	sum-=(2*z2);
	System.out.println(sum);
	}
 
}
	
	
	
	  	 	static class SegmentTree{
	   	 		int[] arr , sTree;
	   	 	static	int N;
	   	 		public SegmentTree(int[] in){
	   	 			arr=in;
	   	 		N=arr.length-1;
	   	 			sTree=new int[2*N];
	   	 			
	   	 			build(1,1,N);
	   	 		}
	   	 		public void build(int node, int l, int r){
	   	 			if(l==r){
	   	 				sTree[node]=arr[l];
	   	 			}
	   	 			else{
	   	 				int leftchild=node*2;
	   	 				int rightchild=node*2+1;
	   	 				int mid =(l+r)/2;
	   	 				build(leftchild,l,mid);
	   	 				build(rightchild,mid+1,r);
	   	 				sTree[node]=sTree[leftchild]&sTree[rightchild];
	   	 			}
	   	 		}
	   	 		public  void update(int i, int val){
	   	 			int node =i+N-1;
	   	 			arr[i]=val;
	   	 			sTree[node]=val;
	   	 			node=node/2;
	   	 			while(node>0){
	   	 			int leftchild=node *2;
   	 				int rightchild=node*2+1;
   	 			sTree[node]=sTree[leftchild]&sTree[rightchild];
   	 			node=node/2;
	   	 			}
	   	 			return;
	   	 			
	   	 		}
	   	 		public int query(int i, int j){
	   	 			 return query(1,1, N,  i, j);
	   	 		}
	   	 		public int query(int node,int l, int r, int i , int j){
	   	 			if(i>r||j<l){
	   	 				return 1<<30;
	   	 			}
	   	 			if(i<=l&&r<=j){
	   	 				return sTree[node];
	   	 			}
	   	 		int leftchild=node*2;
	 				int rightchild=node*2+1;
	 				int mid =(l+r)/2;
	 				
	 			return	query(leftchild,l,mid,i,j)&query(rightchild,mid+1,r,i,j);
	 				
	   	 		}
	   	 	}


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}
 
		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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}}