You are given two sequences $a_1, a_2, \dots, a_n$ and $b_1, b_2, \dots, 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 $\sum_{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 \le t \le 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 \le x_1, y_1, z_1 \le 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 \le x_2, y_2, z_2 \le 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\}$

Difficulty: interview

Starter code:

Solutions:
for _ in range(int(input())):
    a,b,c = list(map(int, input().split()))
    x,y,z = list(map(int, input().split()))

    temp = min(c,y)
    ans = 2*temp
    c -= temp
    y -= temp
    temp = min(c,z)
    c -= temp
    z -= temp
    temp = min(c,x)
    c -= temp
    x -= temp

    temp = min(a,z)
    a -= temp
    z -= temp
    temp = min(b,z)
    ans -= 2*temp
    b -= temp
    z -= temp
    print(ans)


import sys
input = sys.stdin.readline

T = int(input())

for t in range(T):
    x1, y1, z1 = [int(_) for _ in input().split()]
    x2, y2, z2 = [int(_) for _ in input().split()]
    pos_ass = min(z1, y2)
    z1 -= pos_ass
    y2 -= pos_ass
    if y1 > x2 + y2:
        neg_ass = y1 - (x2 + y2)
    else:
        neg_ass = 0
    print(2*(pos_ass-neg_ass))


from queue import Queue

def rn():
    a = int(input())
    return a


def rl():
    a = list(map(int, input().split()))
    return a

for _ in range(rn()):
    [x1,y1,z1] = rl()
    [x2, y2, z2] = rl()
    ans = 0
    h1 = min(z1,y2)
    ans += 2*h1
    z1 -= h1
    y2 -= h1
    rem = x1+z1
    h2 = min(rem,z2)
    z2 -= h2
    ans -= 2*z2
    print(ans)




import sys
input = sys.stdin.readline
for f in range(int(input())):
    x1,y1,z1=map(int,input().split())
    x2,y2,z2=map(int,input().split())
    sol=0
    foo=min(z1,y2)
    sol+=2*foo
    z1-=foo
    y2-=foo
    y1-=y2
    y1-=x2
    if y1>0:
        sol-=2*y1
    print(sol)

for _ in range(int(input())):
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    m = min(a[2], b[1])
    a[2] -= m
    b[1] -= m
    res += 2*m
    
    m = min(a[1], b[0])
    a[1] -= m
    b[0] -= m
    m = min(a[1], b[1])
    a[1] -= m
    b[1] -= m

    m = min(a[0], b[2])
    a[0] -= m
    b[2] -= m
    m = min(a[2], b[2])
    a[2] -= m
    b[2] -= m

    res -= min(a[1], b[2]) * 2
    print(res)


for _ in range(int(input())):
    a, b, c = list(map(int, input().split()))
    x, y, z = list(map(int, input().split()))
    print(2 * min(c, y) - 2 * max(0, min(z - max(c - y, 0) - a, b)))

import sys

T = int(sys.stdin.readline().strip())
for t in range (0, T):
    x1, y1, z1 = list(map(int, sys.stdin.readline().strip().split()))
    x2, y2, z2 = list(map(int, sys.stdin.readline().strip().split()))
    n = x1 + y1 + z1
    print(2 * min(z1, y2) - 2 * max(0, y1 - (x2 + y2 - min(z1, y2))))

for nt in range(int(input())):
	x1,y1,z1 = map(int,input().split())
	x2,y2,z2 = map(int,input().split())
	a = min(x1,z2)
	z2,x1 = z2-a,x1-a
	if z2==0:
		ans = min(z1,y2)*2
	else:
		z1,z2 = z1-min(z1,z2),z2-min(z1,z2)
		if z2==0:
			ans = min(z1,y2)*2
		else:
			ans = -(z2*2)
	print (ans)

for _ in range(int(input())):
    x1,y1,z1=list(map(int,input().split()))
    x2,y2,z2=list(map(int,input().split()))
    k=min(z1,y2)
    ans=k*2
    z1-=k
    y2-=k
    
    k=min(z2,x1)
    z2-=k
    x1-=k
    z2-=z1
    
    if z2>0:
        ans-=z2*2
        
    print(ans)
    
    
    
    # if k<=n:
    #     if n%2==k%2:
    #         print(0)
    #     else:
    #         print(1)
    # else:
    #     print(k-n)


t = int(input())
for _ in range(t):
    xyz1 = list(map(int, input().split()))
    xyz2 = list(map(int, input().split()))
    ans = min(xyz1[2], xyz2[1]) * 2
    xyz1[2] -= ans // 2
    xyz2[1] -= ans // 2
    tmp = xyz2[2] - xyz1[0] - xyz1[2]
    tmp = max(tmp, 0)
    ans -= tmp * 2
    print(ans)


def solve():
    u, v, w = map(int, input().split())
    x, y, z = map(int, input().split())
    ans = min(w, y) * 2
    w, y = w - min(w, y), y - min(w, y)
    z, u = z - min(z, u), u - min(z, u)
    z, w = z - min(z, w), w - min(z, w)
    v, x = v - min(v, x), u - min(v, x)
    v, y = v - min(v, y), v - min(v, y)
    ans -= min(v, z) * 2
    print(ans)
t = int(input())
for _ in range(t):
    solve()

gans = []
for _ in range(int(input())):
    a0, a1, a2 = list(map(int, input().split()))
    b0, b1, b2 = list(map(int, input().split()))
    a0, b2 = a0 - min(a0, b2), b2 - min(a0, b2)
    a2, b2 = a2 - min(a2, b2), b2 - min(a2, b2)
    ans = -b2 * 2
    a1 -= b2
    b2 = 0
    ans += min(a2, b1) * 2
    a2, b1 = a2 - min(a2, b1), b1 - min(a2, b1)
    gans.append(ans)
print('\n'.join(map(str, gans)))


def main():
    x1, y1, z1 = [int(s) for s in input().split()]
    x2, y2, z2 = [int(s) for s in input().split()]
    plus = min(z1, y2)
    remain = z1 - plus
    
    minus = max(z2 - remain - x1, 0)
    return (plus - minus) * 2

tests = int(input())
for _ in range(tests):
    print(main())

t = int(input())

for i in range(t):
    x1,y1,z1 = list(map(int,input().split()))
    x2,y2,z2 = list(map(int,input().split()))
    ans = 0
    a = min(z1,y2)
    z1 -= a
    y2 -= a
    ans += 2*a
    b = z2 - min(x1+z1,z2)
    ans -= 2*b
    print(ans)

for i in range(int(input())):
	a0, a1, a2 = list(map(int, input().split()))
	b0, b1, b2 = list(map(int, input().split()))

	twos = min(a2, b1)

	a2 -= twos
	b1 -= twos

	zeros = min(a1, b0+b1)

	a1 -= zeros
	
	ones = min(a1, b2)

	print(twos*2-ones*2)

t=int(input())
for _ in range(t):
	a,b,c=map(int,input().split())
	x,y,z=map(int,input().split())
	ans=0
	t=min(c,y)
	c-=t
	y-=t
	ans+=t*2
	t=min(z,c)
	z-=t
	c-=t
	t=min(z,a)
	z-=t
	a-=t
	ans-=min(z,b)*2
	print(ans)

from math import ceil
from sys import stdin, stdout, setrecursionlimit
from random import randint

for _ in range(int(input())):
    x1, y1, z1 = list(map(int, input().split()))
    x2, y2, z2 = list(map(int, input().split()))
    x = min(z1, y2)
    z1 -= x
    y2 -= x
    ans = x * 2
    z2 = max(0, z2 - z1 - x1)
    print(ans - min(z2, y1) * 2)




import sys
# sys.setrecursionlimit(10**6) 
input=sys.stdin.readline
t=int(input())
for t1 in range(t):
    x1,y1,z1=list(map(int,input().split(" ")))
    x2,y2,z2=list(map(int,input().split(" ")))
    ans=min(z1,y2)*2
    z1-=ans//2
    y2-=ans//2
    t1=min(y1,x2)
    y1-=t1
    x2-=t1
    t1=min(y2,y1)
    y1-=t1
    y2-=t1
    ans-=min(y1,z2)*2
    print(ans)

q = int(input())
for _ in range(q):
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))
	myk = min(a[2],b[1])
	wyn = 0
	a[2] -= myk
	b[1] -= myk
	wyn += 2*myk
	cyk = b[0]+b[1]
	dup = a[1]
	al = sum(a)
	wyn -= (max(0,dup-cyk))*2
	print(wyn)


t = int(input())
for i in range(t):
    a0, a1, a2 = map(int , input().split())
    b0, b1, b2 = map(int , input().split())

    ans = 2*min(a2,b1)
    a2 = max(0 , a2 - min(a2,b1))

    if b2 > (a0+a2):
        ans -= (2*(b2 - a0 - a2))
    print(ans)