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\}$

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Mathematics

Constructive algorithms


Solutions:
import io
import os
from collections import Counter, defaultdict, deque

def solve(XYZ1, XYZ2):
	(X1, Y1, Z1) = XYZ1
	(X2, Y2, Z2) = XYZ2
	ans = 0
	temp = min(Z1, Y2)
	Z1 -= temp
	Y2 -= temp
	ans += temp * 2
	temp = max(Y1 + Z2 - (X1 + Y1 + Z1), 0)
	ans -= temp * 2
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	XYZ1 = [int(x) for x in input().split()]
	XYZ2 = [int(x) for x in input().split()]
	ans = solve(XYZ1, XYZ2)
	print(ans)


for _ in range(int(input())):
	(x0, x1, x2) = [int(__) for __ in input().split()]
	(y0, y1, y2) = [int(___) for ___ in input().split()]
	ans = 0
	if x2 >= y1:
		ans += 2 * y1
		x2 -= y1
		if x2 <= y2:
			y2 -= x2
			if x0 <= y2:
				y2 -= x0
				ans -= 2 * y2
	else:
		ans += 2 * x2
		if y2 >= x0:
			y2 -= x0
			ans -= 2 * y2
	print(ans)


for _ in range(int(input())):
	(zer, on, tw) = [int(c) for c in input().split()]
	(zero, one, two) = [int(c) for c in input().split()]
	s = 0
	s += min(tw, one) * 2
	k = min(tw, one)
	tw -= k
	one -= k
	if on > one + zero:
		on -= one + zero
		s -= on * 2
	print(s)


import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	ans_ = ''
	for _ in range(int(input())):
		(x1, y1, z1) = read()
		(x2, y2, z2) = read()
		ans = 0
		ans += 2 * min(z1, y2)
		z1 = max(0, z1 - min(z1, y2))
		ans -= 2 * max(0, z2 - (x1 + z1))
		ans_ += str(ans) + '\n'
	print(ans_)
main()


import sys
from math import ceil
from collections import deque
for _ in range(int(input())):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	n = x1 + y1 + z1
	ans = min(z1, y2) * 2
	z1 -= min(z1, y2)
	y2 -= min(z1, y2)
	z2 -= min(x1, z2)
	y1 -= min(x2, y1)
	print(ans - min(z2, y1) * 2)


import sys

def getInput():
	return sys.stdin.readline()[:-1]
cases = int(getInput())
for z in range(cases):
	aStr = getInput().split(' ')
	bStr = getInput().split(' ')
	a = list((int(x) for x in aStr))
	b = list((int(x) for x in bStr))
	score = 2 * min(a[2], b[1])
	a[2] = a[2] - min(a[2], b[1])
	if a[2] + a[0] < b[2]:
		score -= 2 * (b[2] - (a[2] + a[0]))
	print(int(score))


for t in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	result = 0
	if z1 >= y2:
		result += 2 * y2
		z1 = z1 - y2
		if z1 + x1 <= z2:
			result -= 2 * (z2 - z1 - x1)
	else:
		result += 2 * z1
		y2 -= z1
		if z2 > x1:
			result -= 2 * (z2 - x1)
	print(result)


n = int(input())
values_a = []
values_b = []

def fa(x):
	if x < 0:
		return 0
	else:
		return x
for x in range(n):
	(a, b, c) = map(int, input().split())
	_tuple = (a, b, c)
	values_a.append(_tuple)
	(d, e, f) = map(int, input().split())
	_tuple = (d, e, f)
	values_b.append(_tuple)
for i in range(n):
	max_sum = 2 * min(values_a[i][2], values_b[i][1])
	min_sub = 2 * fa(values_b[i][2] - values_a[i][2] + min(values_a[i][2], values_b[i][1]) - values_a[i][0])
	print(max_sum - min_sub)


def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if z2 == 0:
		return min(z1, y2) * 2
	temp = min(x1, z2)
	x1 -= temp
	z2 -= temp
	if x2 >= y1:
		z2 = 0
		y1 = 0
		return min(y2, z1) * 2
	y1 -= x2
	if z1 >= z2:
		z1 -= z2
		return min(y2, z1) * 2
	z2 -= z1
	return min(z2, y1) * 2 * -1
t = int(input())
while t != 0:
	res = solve()
	print(res)
	t -= 1


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

def inIList():
	return list(map(int, input().split()))

def inSList():
	return input().split()

def solve():
	a = inIList()
	b = inIList()
	s = 0
	pb = b[2]
	b[2] -= a[0]
	a[0] = max(a[0] - pb, 0)
	if b[2] <= 0:
		b[2] = 0
	else:
		pb = b[2]
		b[2] -= a[2]
		a[2] = max(a[2] - pb, 0)
		if b[2] <= 0:
			b[2] = 0
		else:
			s -= b[2] * 2
	s += 2 * min(a[2], b[1])
	return s
tests = inInt()
for case in range(tests):
	print(solve())


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


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(x1, y1, z1) = map(int, inputi().split())
	(x2, y2, z2) = map(int, inputi().split())
	c21 = min(z1, y2)
	res = (c21 - max(0, z2 - (z1 - c21) - x1)) * 2
	print(res)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
sys.setrecursionlimit(10 ** 6)
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
sys.setrecursionlimit(10 ** 6)
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	ans += 2 * min(z1, y2)
	k = min(z1, y2)
	y2 -= k
	z1 -= k
	k = min(y1, x2 + y2)
	y1 -= k
	if y1 == 0:
		print(ans)
	else:
		z2 -= min(z1 + x1, z2)
		ans -= 2 * min(z2, y1)
		print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	sum1 = min([z1, y2])
	z1 = z1 - sum1
	sum1 = sum1 * 2
	b = min([z2, x1])
	z2 = z2 - b
	b = min([z2, z1])
	z2 = z2 - b
	if z2 == 0:
		print(sum1)
	else:
		print(sum1 - z2 * 2)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	cnt = 0
	if z1 > 0 and y2 > 0:
		if z1 >= y2:
			cnt += 2 * y2
			z1 -= y2
			y2 = 0
		else:
			cnt += 2 * z1
			y2 -= z1
			z1 = 0
	if x1 > 0 and z2 > 0:
		if x1 >= z2:
			x1 -= z2
			z2 = 0
		else:
			z2 -= x1
			x1 = 0
	if x1 > 0 and y2 > 0:
		if x1 >= y2:
			x1 -= y2
			y2 = 0
		else:
			y2 -= x1
			x1 = 0
	if x1 > 0 and x2 > 0:
		if x1 >= x2:
			x1 -= x2
			x2 = 0
		else:
			x2 -= x1
			x1 = 0
	if y1 > 0 and y2 > 0:
		if y1 >= y2:
			y1 -= y2
			y2 = 0
		else:
			y2 -= y1
			y1 = 0
	if y1 > 0 and x2 > 0:
		if y1 >= x2:
			y1 -= x2
			x2 = 0
		else:
			x2 -= y1
			y1 = 0
	if z1 > 0 and x2 > 0:
		if z1 >= x2:
			z1 -= x2
			x2 = 0
		else:
			x2 -= z1
			z1 = 0
	if y1 > 0 and z2 > 0:
		if y1 >= z2:
			cnt -= 2 * z2
			y1 -= z2
			z2 = 0
		else:
			cnt -= 2 * y1
			y1 -= z2
			z2 = 0
	print(cnt)


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


tc = int(input())
while tc > 0:
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	good = min(z1, y2)
	ans = 2 * good
	z1 = z1 - good
	y2 = y2 - good
	n = x1 + y1 + z1
	if y1 + z2 >= n:
		bad = y1 + z2 - n
		ans = ans - 2 * bad
	print(ans)
	tc = tc - 1


Ans = []
t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	s = x1 + (z1 - min(z1, y2))
	if z2 <= s:
		Ans.append(min(z1, y2) * 2)
	else:
		Ans.append(2 * (min(z1, y2) - z2 + s))
for i in Ans:
	print(i)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c1 = min(z1, y2)
	z1 -= c1
	y2 -= c1
	c = c1 * 2
	c2 = min(z1, z2)
	z1 -= c2
	z2 -= c2
	c3 = min(z1, x2)
	z1 -= c3
	x2 -= c3
	c4 = min(x1, z2)
	x1 -= c4
	z2 -= c4
	c -= z2 * 2
	print(c)


for _ in [0] * int(input()):
	a = list(map(lambda x: int(x), input().split()))
	b = list(map(lambda x: int(x), input().split()))
	sum = 0
	if a[2] >= b[1]:
		a[2] -= b[1]
		sum += 2 * b[1]
		b[1] = 0
	else:
		b[1] -= a[2]
		sum += 2 * a[2]
		a[2] = 0
	if a[2] >= b[2]:
		a[2] -= b[2]
		b[2] = 0
	else:
		b[2] -= a[2]
		a[2] = 0
	if b[2] >= a[0]:
		b[2] -= a[0]
		a[0] = 0
	else:
		b[2] = 0
	if b[2] >= a[1]:
		b[2] -= a[1]
		sum -= 2 * a[1]
	else:
		sum -= 2 * b[2]
		b[2] = 0
	print(sum)


def max_sum(x1, y1, z1, x2, y2, z2):
	return 2 * min(z1, y2) - max(0, 2 * (z2 - (x1 + z1 - min(z1, y2))))
num_tests = int(input())
for _ in range(num_tests):
	(x1, y1, z1) = input().split()
	(x2, y2, z2) = input().split()
	print(max_sum(int(x1), int(y1), int(z1), int(x2), int(y2), int(z2)))


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for i in range(t):
		maxi = 0
		first = list(map(int, input().split()))
		second = list(map(int, input().split()))
		if first[2] <= second[1]:
			maxi += 2 * first[2]
			second[1] = second[1] - first[2]
			first[2] = 0
		else:
			maxi += 2 * second[1]
			first[2] = first[2] - second[1]
			second[1] = 0
		if first[2] >= second[2]:
			first[2] -= second[2]
			second[2] = 0
		else:
			second[2] -= first[2]
			first[2] = 0
		if first[0] >= second[2]:
			first[0] -= second[2]
			second[2] = 0
		else:
			second[2] -= first[0]
			first[0] = 0
		if first[1] >= second[0]:
			first[1] -= second[0]
			second[0] = 0
		else:
			second[0] -= first[1]
			first[1] = 0
		if first[1] >= second[1]:
			first[1] -= second[1]
			second[1] = 0
		else:
			second[1] -= first[1]
			first[1] = 0
		maxi -= 2 * min(first[1], second[2])
		print(maxi)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	a = lis()
	b = lis()
	ans = 0
	if a[2] >= b[1]:
		ans += b[1] * 2
		a[2] -= b[1]
		if a[2] + a[0] >= b[2]:
			print(ans)
		else:
			print(ans - 2 * (b[2] - a[2] - a[0]))
	else:
		ans += a[2] * 2
		b[1] -= a[2]
		if a[0] >= b[2]:
			print(ans)
		else:
			print(ans - 2 * (b[2] - a[0]))
testcase(int(inp()))


def solve(a, b):
	ans = 0
	if a[2] >= b[1]:
		ans += 2 * b[1]
		a[2] -= b[1]
		b[2] -= a[2]
		if b[2] < 0:
			b[2] = 0
		a[2] = 0
	else:
		ans += a[2] * 2
		a[2] = 0
	b[2] -= a[0]
	if b[2] < 0:
		b[2] = 0
	else:
		ans -= b[2] * 2
	print(ans)
t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(a, b)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(x, y, z) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	two = min(z, b)
	z -= two
	b -= two
	z -= min(z, c)
	z -= min(z, c)
	one = min(y, b)
	y -= one
	b -= one
	mone = min(y, a)
	y -= mone
	mtwo = min(c, y)
	print((two - mtwo) * 2)
	t -= 1


for i in range(int(input())):
	(a1, b1, c1) = [int(i) for i in input().split()]
	(a2, b2, c2) = [int(i) for i in input().split()]
	x = 0
	x = min(b2, c1) * 2
	c1 = c1 - x // 2
	b2 = b2 - x // 2
	y = c2 - c1 - a1
	if y > 0:
		x = x - min(b1, y) * 2
		print(x)
	else:
		print(x)


f = lambda : map(int, input().split())
for _ in range(int(input())):
	(za, oa, ta) = f()
	(zb, ob, tb) = f()
	if ta >= ob:
		ta = ta - ob
		s = ob * 2
		ob = 0
	else:
		s = ta * 2
		ob = ob - ta
		ta = 0
	if tb <= ta:
		ta = ta - tb
		tb = 0
	else:
		tb = tb - ta
		ta = 0
	if tb >= za:
		tb = tb - za
		za = 0
	else:
		za = za - tb
		tb = 0
	if tb and oa:
		s = s - 2 * min(tb, oa)
	print(s)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = min(c, y)
	b -= min(b, x + max(0, y - c))
	ans -= b
	print(ans * 2)


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


def ternary(x1, y1, z1, x2, y2, z2):
	ans = 0
	if z1 >= y2:
		ans += 2 * y2
		z1 -= y2
		y2 = 0
	else:
		ans += 2 * z1
		y2 -= z1
		z1 = 0
	if z2 >= z1:
		z2 -= z1
		z1 = 0
	else:
		z2 = 0
		z1 -= z2
	if z2 >= x1:
		z2 -= x1
		x1 = 0
	else:
		z2 = 0
		x1 -= z2
	if z2 != 0:
		if z2 >= y1:
			ans -= 2 * y1
			z2 -= y1
			y1 = 0
		else:
			ans -= 2 * z2
			y1 -= z2
			z2 = 0
	if y2 >= y1:
		y2 -= y1
		y1 = 0
	else:
		y1 -= y2
		y2 = 0
	return ans
t = int(input())
a = []
for i in range(t):
	(x1, y1, z1) = list(map(int, input().split(' ')))
	(x2, y2, z2) = list(map(int, input().split(' ')))
	a.append([x1, y1, z1, x2, y2, z2])
for x in a:
	print(ternary(*x))


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	ans = 0
	if b < z:
		ans += b * 2
		rem_z = z - b
	else:
		ans += 2 * z
		rem_z = 0
	if c > x + rem_z:
		ans -= 2 * (c - x - rem_z)
	print(ans)


def mlt():
	return map(int, input().split())

def solv():
	(zr1, on1, tw1) = mlt()
	(zr2, on2, te2) = mlt()
	gain = min(tw1, on2) * 2
	tw1 -= gain // 2
	on2 -= gain // 2
	if on2 > tw1:
		if zr1 >= te2:
			print(gain)
			return
		te2 -= zr1
		gain -= 2 * te2
		print(gain)
		return
	elif tw1 + zr1 >= te2:
		print(gain)
		return
	else:
		te2 -= tw1 + zr1
		gain -= 2 * te2
		print(gain)
for n in range(int(input())):
	solv()


from sys import *
input = stdin.readline
t = int(input())
for case in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	add_cnt = min(z1, y2)
	rest = z1 - add_cnt
	sub_cnt = z2 - min(x1 + rest, z2)
	Ans = 2 * (add_cnt - sub_cnt)
	print(Ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	(a0, a1, a2) = RL()
	(b0, b1, b2) = RL()
	if a0 >= b2:
		print(min(b1, a2) * 2)
	else:
		r1 = min(b1, a2) * 2
		if a2 > b1:
			r2 = max(0, b2 - a0 - (a2 - b1)) * 2
		else:
			r2 = (b2 - a0) * 2
		print(r1 - r2)


t = int(input())
while t > 0:
	t -= 1
	line = input().split(' ')
	a0 = int(line[0])
	a1 = int(line[1])
	a2 = int(line[2])
	line = input().split(' ')
	b0 = int(line[0])
	b1 = int(line[1])
	b2 = int(line[2])
	m = min(a2, b1)
	sum = m * 2
	a2 -= m
	b1 -= m
	m = min(a0, b2)
	a0 -= m
	b2 -= m
	m = min(a1, b0)
	a1 -= m
	b0 -= m
	a = [a0, a1, a2]
	b = [b0, b1, b2]
	for i in range(0, 3):
		if a[i] == 0:
			continue
		for j in range(0, 3):
			if b[j] == 0:
				continue
			if i > j:
				m = min(a[i], b[j])
				a[i] -= m
				b[j] -= m
				sum += m * (i * j)
			if i == j:
				m = min(a[i], b[j])
				a[i] -= m
				b[j] -= m
			if i < j:
				m = min(a[i], b[j])
				a[i] -= m
				b[j] -= m
				sum -= m * (i * j)
	print(sum)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	sum = 0
	if z >= q:
		temp = q
	else:
		temp = z
	sum += temp * 2
	z -= temp
	q -= temp
	if z != 0:
		if z > r:
			z -= r
			r = 0
		else:
			r -= z
			z = 0
	if r <= x:
		print(sum)
	else:
		print(sum - (r - x) * 2)


def TernarySequence(a, b):
	Total = 0
	MaxPlus = min(a[2], b[1])
	a[2] -= MaxPlus
	b[1] -= MaxPlus
	Total += MaxPlus * 2
	MaxSubtraction = max(0, b[2] - a[2] - a[0])
	Total -= MaxSubtraction * 2
	return Total
t = int(input())
Result = list()
for i in range(t):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	Result.append(TernarySequence(a, b))
for r in Result:
	print(r)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(a, b, c) = iia()
	(a1, b1, c1) = iia()
	t1 = min(c, b1)
	tot = t1 * 2
	c -= t1
	b1 -= t1
	t2 = min(a + c, c1)
	c1 -= t2
	tot -= min(c1, b) * 2
	print(tot)


t = int(input())
for i in range(t):
	t = 0
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = min(z1, y2)
	t = c * 2
	z1 -= c
	y2 -= c
	c = min(x1, z2)
	x1 -= c
	z2 -= c
	if z2 == 0 or z2 <= z1:
		print(t)
	elif z2 > z1:
		t = t - 2 * (z2 - z1)
		print(t)


def sum1(arr1, arr2):
	m = min(arr1[0], arr2[2])
	arr1[0] -= m
	arr2[2] -= m
	m = min(arr1[1], arr2[0])
	arr1[1] -= m
	arr2[0] -= m
	m = min(arr1[2], arr2[1])
	arr1[2] -= m
	arr2[1] -= m
	result = 2 * m
	result -= 2 * min(arr1[1], arr2[2])
	return result
a = int(input())
for i in range(a):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(sum1(a, b))


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


nums = int(input())
A = []
B = []
for i in range(nums):
	A.append(input().split())
	B.append(input().split())
for zumba in range(nums):
	(A_0, A_1, A_2) = [int(ciccio) for ciccio in A[zumba]]
	(B_0, B_1, B_2) = [int(ciccio) for ciccio in B[zumba]]
	A_2_bar = A_2 - min(A_2, B_1)
	print(2 * min(A_2, B_1) - 2 * max(0, B_2 - A_0 - A_2_bar))


tests = int(input())
for i in range(tests):
	(a0, a1, a2) = list(map(int, input().split()))
	(b0, b1, b2) = list(map(int, input().split()))
	maxSum = 0
	maxSum += 2 * min(a2, b1)
	temp = min(a2, b1)
	a2 -= temp
	b1 -= temp
	temp = min(b2, a0)
	a0 -= temp
	b2 -= temp
	temp = min(a2, b2)
	a2 -= temp
	b2 -= temp
	temp = min(a1, b1)
	a1 -= temp
	b1 -= temp
	temp = min(a1, b0)
	a1 -= temp
	b0 -= temp
	maxSum -= 2 * min(a1, b2)
	print(maxSum)


for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	positive_score = min(a2, b1) * 2
	leftover_2s = max(0, a2 - b1)
	negative_score = min(max(0, b2 - (a0 + leftover_2s)), a1) * 2
	print(positive_score - negative_score)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math

def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	to = min(z1, y2)
	z1 -= to
	y2 -= to
	tt = min(z1, z2)
	z1 -= tt
	z2 -= tt
	tz = min(z1, x2)
	z1 -= tz
	x2 -= tz
	oo = min(y1, y2)
	y1 -= oo
	y2 -= oo
	oz = min(y1, x2)
	y1 -= oz
	x2 -= oz
	ot = min(y1, z2)
	y1 -= ot
	z2 -= ot
	print(to * 2 - ot * 2)
for _ in range(int(input())):
	solve()


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(a1, b1, c1) = list(map(int, sys.stdin.readline().rstrip().split()))
	(a2, b2, c2) = list(map(int, sys.stdin.readline().rstrip().split()))
	re = 0
	two_cnt = min(c1, b2)
	c1 -= two_cnt
	b2 -= two_cnt
	re += two_cnt * 2
	one_cnt = min(b1, b2)
	b1 -= one_cnt
	b2 -= one_cnt
	one_cnt = min(b1, a2)
	b1 -= one_cnt
	a2 -= one_cnt
	zero_cnt = min(a1, c2)
	a1 -= zero_cnt
	c2 -= zero_cnt
	minus_cnt = min(b1, c2)
	re -= minus_cnt * 2
	print(re)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(a0, a1, a2) = MAP()
	(b0, b1, b2) = MAP()
	ans = 0
	use = min(a2, b1)
	ans += use * 2
	a2 -= use
	b1 -= use
	use = min(a0, b2)
	a0 -= use
	b2 -= use
	use = min(a2, b2)
	a2 -= use
	b2 -= use
	use = min(a0, b1)
	a0 -= use
	b1 -= use
	use = min(a1, b1)
	a0 -= use
	b1 -= use
	ans -= b1 + b2 * 2
	print(ans)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	result = 0
	cur = min(z1, y2)
	z1 -= cur
	y2 -= cur
	result += 2 * cur
	cur = min(z2, x1)
	z2 -= cur
	x1 -= cur
	cur = min(z2, z1)
	z2 -= cur
	z1 -= cur
	result -= 2 * z2
	print(result)


for _ in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	summ = 0
	towsones = min(z1, y2)
	summ += towsones * 2
	z1 -= towsones
	y2 -= towsones
	onesones = min(y1, y2)
	y1 -= onesones
	y2 -= onesones
	zeroestows = min(x1, z2)
	x1 -= zeroestows
	z2 -= zeroestows
	towstows = min(z1, z2)
	z1 -= towstows
	z2 -= towstows
	onestows = min(y1, z2)
	summ -= onestows * 2
	y1 -= onestows
	z2 -= onestows
	print(summ)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[2] >= b[1] and a[0] >= b[2]:
		res = 2 * b[1]
		print(res)
	elif a[2] >= b[1] and b[2] > a[0]:
		res = 2 * b[1] - 2 * max(0, b[2] - a[0] - (a[2] - b[1]))
		print(res)
	elif b[1] > a[2] and a[0] >= b[2]:
		res = 2 * a[2]
		print(res)
	else:
		res = 2 * a[2] - 2 * (b[2] - a[0])
		print(res)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	print(min(c, e) * 2 - max(0, min(f - a - (c - min(c, e)), b)) * 2)


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		a = li()
		b = li()
		s = 0
		p = min(a[2], b[1])
		a[2] -= p
		b[1] -= p
		s += 2 * p
		p = min(a[2], b[2])
		a[2] -= p
		b[2] -= p
		p = min(a[0], b[2])
		a[0] -= p
		b[2] -= p
		p = min(a[1], b[2])
		s -= 2 * p
		print(s)
solve()


def main():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = min(z1, y2) * 2
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(y1, x2)
	y1 -= m
	x2 -= m
	ans -= min(y1, z2) * 2
	print(ans)
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	_sum = 0
	twos = min(z1, y2)
	z1 -= twos
	y2 -= twos
	_sum += twos * 2
	neg = min(z2, x1 + z1)
	z2 -= neg
	if z2 > 0:
		_sum -= z2 * 2
	print(_sum)


TC = int(input())
while TC > 0:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	positive = min(a[2], b[1])
	a[2] -= positive
	b[1] -= positive
	b[2] -= min(b[2], a[2])
	a[1] -= min(a[1], b[1])
	a[1] -= min(a[1], b[0])
	b[2] -= min(b[2], a[0])
	print(positive * 2 - 2 * min(b[2], a[1]))
	TC -= 1


from collections import Counter, defaultdict as dft

def mp():
	return map(int, input().split())

def ml():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(x1, y1, z1) = mp()
	(x2, y2, z2) = mp()
	mx = 2 * min(z1, y2)
	y1 -= min(y1, x2)
	z2 -= min(z2, x1)
	mx -= 2 * min(y1, z2)
	print(mx)


test = int(input())
for t in range(test):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	if z1 >= y2:
		ans += y2 * 2
		z1 -= y2
		y2 -= y2
	else:
		ans += z1 * 2
		z1 -= z1
		y2 -= z1
	if z2 > x1:
		z2 -= x1
		if z2 > 0:
			z2 -= z1
			if z2 < 0:
				z2 = 0
		ans -= z2 * 2
	print(ans)


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


t = int(input())
for t1 in range(t):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	m = min(x0, y2)
	x0 -= m
	y2 -= m
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x2, y1)
	ans = 0
	x2 -= m
	y1 -= m
	ans += 2 * m
	ans -= 2 * min(x1, y2)
	print(ans)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		sumi = min(z1, y2) * 2
		qq = y2 - min(z1, y2) + x2
		sumi -= max(0, y1 - qq) * 2
		print(sumi)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


T = int(input())
while T:
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	z = max(0, z - a)
	s = 0
	if z >= c:
		s -= min(z - c, b) * 2
	else:
		s += min(c - z, y) * 2
	print(s)
	T = T - 1


n = int(input())
for i in range(n):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = min(a[2], b[1]) * 2
	a[2] = a[2] - ans // 2
	if b[2] <= a[0]:
		print(ans)
	else:
		b[2] = b[2] - a[0]
		if b[2] <= a[2]:
			print(ans)
		else:
			b[2] = b[2] - a[2]
			print(ans - b[2] * 2)


for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if z2 - x1 > 0:
		if z1 <= y2:
			z12 = 0
		else:
			z12 = z1 - y2
		if z2 - x1 - z12 > 0:
			sum1 = 2 * min(z1, y2) - 2 * min(y1, z2 - x1 - z12)
		else:
			sum1 = 2 * min(z1, y2)
	else:
		sum1 = 2 * min(z1, y2)
	print(sum1)


for _ in range(int(input())):
	sum = 0
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	m = min(x0, y2)
	x0 -= m
	y2 -= m
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	sum += 2 * m
	sum -= 2 * min(x1, y2)
	print(sum)


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


for i1 in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	add = min(z1, y2) * 2
	z1 = z1 - min(z1, y2)
	z2 = z2 - x1
	z2 = z2 - z1
	sub = 0
	if z2 > 0:
		sub = min(y1, z2) * 2
	print(add - sub)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = 0
	while x1 > 0:
		if z2 > 0:
			if z2 >= x1:
				z2 = z2 - x1
				x1 = 0
			else:
				x1 = x1 - z2
				z2 = 0
		elif x2 > 0:
			if x2 >= x1:
				x2 -= x1
				x1 = 0
			else:
				x1 -= x2
				x2 = 0
		elif y2 >= x1:
			y2 -= x1
			x1 = 0
		else:
			x1 -= y2
			y2 = 0
	while z1 > 0:
		if y2 > 0:
			if y2 >= z1:
				c += z1 * 2
				y2 -= z1
				z1 = 0
			else:
				c += y2 * 2
				z1 -= y2
				y2 = 0
		elif z2 > 0:
			if z2 >= z1:
				z2 -= z1
				z1 = 0
			else:
				z1 -= z2
				z2 = 0
		elif x2 >= z1:
			x2 -= z1
			z1 = 0
		else:
			z1 -= x2
			x2 = 0
	if z2 > 0:
		c -= z2 * 2
	print(c)


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


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a[2], b[1])
	a[2] -= c
	b[1] -= c
	ans = 0
	ans += c * 2
	d = max(0, b[2] - a[0] - a[2])
	ans -= d * 2
	print(ans)


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 ternary_sequence(x0: int, y0: int, z0: int, x1: int, y1: int, z1: int) -> int:
	cum_sum = 0
	two = min(z0, y1)
	cum_sum = two * 2
	z0 = z0 - two
	y1 = y1 - two
	elim_twos = min(x0, z1)
	z1 -= elim_twos
	x0 -= elim_twos
	elim_twos = min(z0, z1)
	z1 -= elim_twos
	z0 -= elim_twos
	return cum_sum + -2 * z1
t = int(input())
for _ in range(t):
	(x0, y0, z0) = map(int, input().split(' '))
	(x1, y1, z1) = map(int, input().split(' '))
	print(ternary_sequence(x0, y0, z0, x1, y1, z1))


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	total = 0
	pr = min(a[2], b[1])
	total += pr * 2
	a[2] = a[2] - pr
	b[1] = b[1] - pr
	nr0 = min(a[0], b[2])
	a[0] = a[0] - nr0
	b[2] = b[2] - nr0
	nr2 = min(a[2], b[2])
	a[2] = a[2] - nr2
	b[2] = b[2] - nr2
	total += b[2] * -2
	print(total)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(one, two, three) = list(map(int, input().split()))
		(one1, two1, three1) = list(map(int, input().split()))
		ans = 2 * min(three, two1)
		tem = min(three, two1)
		three -= tem
		two1 -= tem
		if three1:
			tem1 = min(three1, one)
			three1 -= tem1
			one - tem1
		if three1 and three:
			tem2 = min(three1, three)
			three1 -= tem2
			three -= tem2
		ans -= three1 * 2
		yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


def solve(a_0, a_1, a_2, b_0, b_1, b_2) -> int:
	sec_sum = 0
	if b_2 <= a_0:
		a_0 = a_0 - b_2
		b_2 = 0
	else:
		b_2 = b_2 - a_0
		a_0 = 0
	if b_2 > 0:
		if a_2 > b_2:
			a_2 = a_2 - b_2
			b_2 = 0
		else:
			b_2 = b_2 - a_2
			a_2 = 0
	if b_2 > 0:
		sec_sum = -(min(b_2, a_1) * 2)
	if a_2 > 0:
		sec_sum = min(a_2, b_1) * 2
	return sec_sum
T = int(input())
for i in range(T):
	(X_1, Y_1, Z_1) = [int(input_value) for input_value in input().split(' ')]
	(X_2, Y_2, Z_2) = [int(input_value) for input_value in input().split(' ')]
	print(solve(X_1, Y_1, Z_1, X_2, Y_2, Z_2))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
for _ in range(L()[0]):
	(x, y, z) = L()
	(a, b, c) = L()
	f1 = min(z, b)
	z -= f1
	b -= f1
	f2 = min(c, x)
	c -= f2
	x -= f2
	f2 = min(c, z)
	c -= f2
	z -= f2
	print(2 * (f1 - c))
endtime = time.time()


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


t = int(input().split()[0])
for i in range(t):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	n_1 = min(a[2], b[1])
	c = 2 * n_1
	a[2] -= n_1
	b[1] -= n_1
	n_2 = min(a[0] + a[2], b[2])
	b[2] -= n_2
	c -= 2 * b[2]
	print(c)


T = int(input())
i = 0
while i < T:
	(x1, y1, z1) = input().split()
	(x2, y2, z2) = input().split()
	x1 = int(x1)
	y1 = int(y1)
	z1 = int(z1)
	x2 = int(x2)
	y2 = int(y2)
	z2 = int(z2)
	if z2 >= x1 + z1:
		print(-2 * (z2 - x1 - z1))
	elif x1 + z1 > z2 > x1:
		if y2 >= z1 + x1 - z2:
			print(2 * (z1 + x1 - z2))
		else:
			print(2 * y2)
	elif z2 <= x1:
		if y2 >= z1:
			print(2 * z1)
		else:
			print(2 * y2)
	else:
		print(0)
	i = i + 1


testcase = int(input())
for t in range(testcase):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	s = 0
	if x1 <= z2:
		z2 = z2 - x1
		x1 = 0
	else:
		x1 = x1 - z2
		z2 = 0
	if z1 >= y2:
		s = s + y2 * 2
		z1 = z1 - y2
		y2 = 0
	else:
		s = s + z1 * 2
		y2 = y2 - z1
		z1 = 0
	if z2 <= z1:
		z2 = z2 - z1
		z1 = 0
	else:
		z1 = z1 - z2
		z2 = 0
	if y1 >= x2:
		y1 = y1 - x2
		x2 = 0
	else:
		x2 = x2 - y1
		y1 = 0
	if y2 >= y1:
		y2 = y2 - y1
		y1 = 0
	else:
		y1 = y1 - y2
		y2 = 0
	s = s - 2 * y1
	print(s)


import math

def main():
	(one, two, three) = map(int, input().split())
	(one1, two2, three3) = map(int, input().split())
	sm = 0
	dif = min(two2, three)
	sm += 2 * dif
	three -= dif
	two2 -= dif
	if three + one > 0:
		three3 = max(0, three3 - (three + one))
	sm -= three3 * 2
	print(sm)
t = int(input())
for i in range(t):
	main()


t = int(input())
while t > 0:
	t = t - 1
	[x1, y1, z1] = input().split()
	[x2, y2, z2] = input().split()
	x1 = int(x1)
	y1 = int(y1)
	z1 = int(z1)
	x2 = int(x2)
	y2 = int(y2)
	z2 = int(z2)
	ans = 0
	if z1 >= y2:
		ans = ans + 2 * y2
		if x1 + z1 - y2 < z2:
			ans = ans - 2 * (z2 + y2 - z1 - x1)
	else:
		ans = ans + 2 * z1
		if x1 < z2:
			ans = ans - 2 * (z2 - x1)
	print(ans)


def read():
	return [int(x) for x in input().split()]
(cas,) = read()
for _ in range(cas):
	(x1, y1, z1) = read()
	(x2, y2, z2) = read()
	r = 0
	c = min(z1, y2)
	r += c * 2
	z1 -= c
	y2 -= c
	c = min(x1, z2)
	z2 -= c
	x1 -= c
	c = min(z1, z2)
	z1 -= c
	z2 -= c
	r -= 2 * z2
	print(r)


T = int(input())
for test in range(T):
	count1 = [int(x) for x in input().split()]
	count2 = [int(x) for x in input().split()]
	spend = min(count1[2], count2[1])
	ans = 2 * (spend - max(count2[2] - count1[0] - count1[2] + spend, 0))
	print(ans)


def multiple_input():
	return map(int, input().split())

def list_input():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(x1, y1, z1) = multiple_input()
	(x2, y2, z2) = multiple_input()
	ans = min(y2, z1) * 2
	if z1 > y2:
		x1 += z1 - y2
	if x1 < z2:
		ans -= (z2 - x1) * 2
	print(ans)


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


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


import sys
I = lambda : int(input())
readline = lambda : sys.stdin.readline().strip('\n')
RM = readgen = lambda : map(int, readline().split(' '))
for _ in range(I()):
	(a, b) = ([*RM()], [*RM()])
	summ = 0
	minn = min(a[2], b[1])
	a[2] -= minn
	b[1] -= minn
	summ += minn
	minn = min(a[0], b[2])
	a[0] -= minn
	b[2] -= minn
	minn = min(a[2], b[2])
	a[2] -= minn
	b[2] -= minn
	minn = min(a[1], b[2])
	a[2] -= minn
	b[2] -= minn
	summ -= minn
	print(summ * 2)
quit()
for _ in range(I()):
	(n, k) = RM()
	if n <= k:
		print(k - n)
	else:
		print((n - k) % 2)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(x1, y1, z1) = [int(c) for c in input().split()]
	(x2, y2, z2) = [int(c) for c in input().split()]
	ans = 0
	if z1 > 0 and y2 > 0:
		ans += min(z1, y2) * 2
		b = min(z1, y2)
		z1 -= b
		y2 -= b
	if z1 > 0 and z2 > 0:
		b = min(z1, z2)
		z1 -= b
		z2 -= b
	if x1 > 0 and z2 > 0:
		b = min(x1, z2)
		x1 -= b
		z2 -= b
	if y1 > 0 and z2 > 0:
		ans -= min(y1, z2) * 2
	print(ans)


t = int(input())
for _ in range(t):
	(a0, a1, a2) = [int(i) for i in input().split()]
	(b0, b1, b2) = [int(i) for i in input().split()]
	ans = 0
	if b2:
		m = min(b2, a0)
		b2 -= m
		a0 -= m
	if a2:
		m = min(a2, b1)
		ans += m * 2
		a2 -= m
		b1 -= m
	if b2:
		m = min(b2, a2)
		b2 -= m
		a2 -= m
	if b2:
		m = min(b2, a1)
		ans -= m * 2
		b2 -= m
		a1 -= m
	print(ans)


try:
	t = int(input())
	for _ in range(t):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		if z1 == min(z1, y2):
			total = z1 * 2
			y2 = y2 - z1
			if y1 <= y2 + x2:
				print(total)
			else:
				y1 = y1 - (y2 + x2)
				total = total - y1 * 2
				print(total)
		else:
			total = y2 * 2
			z1 = z1 - y2
			if y1 <= x2:
				print(total)
			else:
				y1 = y1 - x2
				total = total - y1 * 2
				print(total)
except:
	pass


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a[2], b[1])
	ans = 2 * x
	a[2] -= x
	b[1] -= x
	neg = max(0, b[2] - a[0] - a[2])
	ans -= 2 * neg
	print(ans)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	(p1, q1, r1) = (x1, y1, z1)
	(p2, q2, r2) = (x2, y2, z2)
	first = min(z1, y2)
	sum1 = 2 * first
	(z1, y2) = (z1 - first, y2 - first)
	second = min(z2, x1)
	(x1, z2) = (x1 - second, z2 - second)
	third = min(y1, x2)
	(y1, x2) = (y1 - third, x2 - third)
	fourth = min(y1, z2)
	sum1 -= 2 * fourth
	print(sum1)


from collections import defaultdict
import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(x1, y1, z1) = get_ints()
	(x2, y2, z2) = get_ints()
	ans = 2 * min(z1, y2)
	z1 -= ans // 2
	y2 -= ans // 2
	(x1, z2) = (x1 - min(x1, z2), z2 - min(x1, z2))
	(z1, x1) = (z1 - min(x1, z1), x1 - min(x1, z1))
	(x1, y2) = (x1 - min(x1, y2), y2 - min(x1, y2))
	(y1, x1) = (y1 - min(x1, y1), x1 - min(x1, y1))
	if z2 > 0:
		k = min(z2, z1)
		z2 -= k
		z1 -= k
		if z2 > 0:
			k = min(z2, y1)
			z2 -= k
			y1 -= k
			ans -= 2 * k
	if y2 > 0:
		k = min(y2, y1)
		y2 -= k
		y1 -= k
		if y2 > 0:
			k = min(z1, y2)
			k -= z1
			k -= y2
			ans -= 2 * k
	print(ans)


import math
from decimal import *

def pf(n):
	ans = [1]
	if n % 2 == 0:
		if n != 2:
			ans.append(2)
		while n % 2 == 0:
			n //= 2
	p = 3
	while n > 1:
		if n % p == 0:
			ans.append(p)
			while n % p == 0:
				n //= p
		p += 1
	return ans
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	mn = min(a[0], b[2])
	a[0] -= mn
	b[2] -= mn
	mn = min(a[2], b[2])
	a[2] -= mn
	b[2] -= mn
	mn = min(a[2], b[1])
	ans += 2 * mn
	a[2] -= mn
	b[1] -= mn
	mn = min(a[1], b[0])
	a[1] -= mn
	b[0] -= mn
	ans -= 2 * min(b[2], a[1])
	print(ans)


import sys
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)


t = int(input())
for _ in range(t):
	(x0, x1, x2) = list(map(int, input().split()))
	(y0, y1, y2) = list(map(int, input().split()))
	r = 0
	m = min(x0, y2)
	x0 -= m
	y2 -= m
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	r += 2 * m
	r -= 2 * min(x1, y2)
	print(r)


from sys import stdin, stdout
import bisect
import math
from collections import deque
mod = 10 ** 9 + 7

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def DFS(dictionary, vertex, visited):
	visited[vertex] = True
	stack = [vertex]
	print(vertex)
	while stack:
		a = stack.pop()
		for i in dictionary[a]:
			if not visited[i]:
				print(i)
				visited[i] = True
				stack.append(i)

def BFS(dictionary, vertex, visited):
	visited[vertex] = True
	q = deque()
	q.append(vertex)
	while q:
		a = q.popleft()
		for i in dictionary[a]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				print(i)

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	(x1, y1, z1) = mp()
	(x2, y2, z2) = mp()
	ans = 2 * min(z1, y2)
	x1 += z1 - min(z1, y2)
	y2 = y2 - min(z1, y2)
	p = z2 - x1
	if p <= 0:
		pr(ans)
	else:
		ans -= 2 * abs(p)
		pr(ans)
for _ in range(inp()):
	solve()


import sys

def FastInt(zero=0):
	(_ord, nums, num, neg) = (lambda x: x, [], zero, False)
	(i, s) = (0, sys.stdin.buffer.read())
	try:
		while True:
			if s[i] >= b'0'[0]:
				num = 10 * num + _ord(s[i]) - 48
			elif s[i] == b'-'[0]:
				neg = True
			elif s[i] != b'\r'[0]:
				nums.append(-num if neg else num)
				(num, neg) = (zero, False)
			i += 1
	except IndexError:
		pass
	if s and s[-1] >= b'0'[0]:
		nums.append(-num if neg else num)
	return nums
inp = FastInt()
ii = 0

def fin(size=None):
	global ii
	if size == None:
		ni = ii
		ii += 1
		return inp[ni]
	else:
		ni = ii
		ii += size
		return inp[ni:ni + size]
_T_ = fin()
for _t_ in range(_T_):
	(a0, a1, a2) = fin(3)
	(b0, b1, b2) = fin(3)
	su = 0
	temp = min(a2, b1)
	su += 2 * temp
	a2 -= temp
	b1 -= temp
	temp = min(a0, b2)
	a0 -= temp
	b2 -= temp
	temp = min(a0, b0)
	a0 -= temp
	b0 -= temp
	temp = min(a1, b1)
	a1 -= temp
	b1 -= temp
	temp = min(a2, b2)
	a2 -= temp
	b2 -= temp
	temp = min(a1, b2)
	su -= 2 * temp
	a1 -= temp
	b2 -= temp
	temp = min(a0, b1)
	a0 -= temp
	b1 -= temp
	print(su)


def tran(nk, arr):
	if arr[2] > nk[0]:
		if nk[2] < arr[1]:
			p = arr[2] - nk[0]
			return min(arr[1], nk[2]) * 2 - 2 * p
		else:
			pm = nk[2] - arr[1]
			p = arr[2] - nk[0]
			if pm > p:
				return min(arr[1], nk[2]) * 2
			else:
				return min(arr[1], nk[2]) * 2 - 2 * (p - pm)
	else:
		return min(arr[1], nk[2]) * 2
t = int(input())
ans = []
for i in range(t):
	nk = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	r = tran(nk, arr)
	ans.append(r)
for i in ans:
	print(i)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if z2 > x1 + z1:
		s = -2 * min((z2 - (x1 + z1), y1))
	elif x1 <= z2 <= x1 + z1:
		s = min(y2, x1 + z1 - z2) * 2
	elif z2 < x1:
		s = min(y2, z1) * 2
	print(s)


for _ in range(int(input())):
	l = [int(x) for x in input().split()]
	m = [int(x) for x in input().split()]
	total = 0
	if l[0] - m[2] >= 0:
		if m[1] - l[2] >= 0:
			total += l[2] * 2
		else:
			total += m[1] * 2
	else:
		m[2] = m[2] - l[0]
		l[0] = 0
		if l[2] - m[2] >= 0:
			l[2] = l[2] - m[2]
			if m[1] - l[2] >= 0:
				total += l[2] * 2
			else:
				total += m[1] * 2
		else:
			m[2] = m[2] - l[2]
			total += -m[2] * 2
	print(total)


for y in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	sum = 0
	q = min(a0, b2)
	a0 -= q
	b2 -= q
	p = min(a1, b0)
	a1 -= p
	b0 -= p
	m = min(a2, b1)
	sum += 2 * m
	a2 -= m
	b1 -= m
	sum -= 2 * min(a1, b2)
	print(sum)


def schet(x_1, y_1, z_1, x_2, y_2, z_2):
	sum = 0
	sum += min(z_1, y_2) * 2
	z_1 -= min(z_1, y_2)
	y_2 -= min(z_1, y_2)
	if z_2 > x_1 + z_1:
		sum -= (z_2 - (x_1 + z_1)) * 2
	return sum
t = int(input())
for i in range(t):
	(x_1, y_1, z_1) = [int(x) for x in input().split()]
	(x_2, y_2, z_2) = [int(x) for x in input().split()]
	print(schet(x_1, y_1, z_1, x_2, y_2, z_2))


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	ans = min(z, y1) * 2 - min(y, max(0, z1 - (max(z, y1) - min(z, y1)) - x)) * 2
	k = min(z, y1) * 2
	k1 = max(z1 - min(z + x - k // 2, z1), 0) * 2
	print(k - k1)


def solve(a, b, c, d, e, f):
	ans = 2 * min(c, e)
	c -= ans // 2
	e -= ans // 2
	m = min(b, d)
	b -= m
	d -= m
	m = min(a, f)
	a -= m
	f -= m
	ans -= 2 * min(b, f)
	return ans
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	print(solve(x1, y1, z1, x2, y2, z2))


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)


t = int(input())
answer = []
for a in range(t):
	sumv = 0
	x = [int(i) for i in input().split()]
	y = [int(i) for i in input().split()]
	m = min(x[0], y[2])
	x[0] -= m
	y[2] -= m
	m = min(x[1], y[0])
	x[1] -= m
	y[0] -= m
	m = min(x[2], y[1])
	x[2] -= m
	y[1] -= m
	sumv += 2 * m
	x = 2 * min(x[1], y[2])
	sumv = sumv - x
	answer.append(sumv)
for b in answer:
	print(b)


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


import sys
input = sys.stdin.readline
from collections import Counter

def read():
	(X1, Y1, Z1) = map(int, input().strip().split())
	(X2, Y2, Z2) = map(int, input().strip().split())
	return (X1, Y1, Z1, X2, Y2, Z2)

def solve(X1, Y1, Z1, X2, Y2, Z2):
	C = 0
	m = min(Z1, Y2)
	C += 2 * m
	Z1 -= m
	Y2 -= m
	m = min(Z1, Z2)
	Z1 -= m
	Z2 -= m
	m = min(Z1, X2)
	Z1 -= m
	X2 -= m
	m = min(Y1, Y2)
	Y1 -= m
	Y2 -= m
	m = min(Y1, X2)
	Y1 -= m
	X2 -= m
	m = min(Y1, Z2)
	C -= 2 * m
	Y1 -= m
	Z2 -= m
	return C
T = int(input().strip())
for t in range(T):
	inputs = read()
	print('%s' % solve(*inputs))


for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	two_x_one = min(z1, y2)
	y2 -= two_x_one
	z1 -= two_x_one
	zero_x_two = min(x1, z2)
	x1 -= zero_x_two
	z2 -= zero_x_two
	zero_x_one = min(x1, y2)
	x1 -= zero_x_one
	y2 -= zero_x_one
	one_x_one = min(y1, y2)
	y1 -= one_x_one
	y2 -= one_x_one
	two_x_two = min(z1, z2)
	z1 -= two_x_two
	z2 -= two_x_two
	one_x_zero = min(y1, x2)
	y1 -= one_x_zero
	x2 -= one_x_zero
	one_x_two = min(y1, z2)
	y1 -= one_x_two
	z2 -= one_x_two
	print(2 * (two_x_one - one_x_two))


for _ in range(int(input())):
	(x1, x2, x3) = map(int, input().split())
	(y1, y2, y3) = map(int, input().split())
	z = min(y2, x3)
	y2 -= z
	x3 -= z
	ans = 2 * z
	z = min(x1, y3)
	x1 -= z
	y3 -= z
	z = min(y1, x2)
	y1 -= z
	x2 -= z
	z = min(y3, x3)
	y3 -= z
	x3 -= z
	z = min(x2, y2)
	x2 -= z
	y2 -= z
	z = min(x2, y1)
	x2 -= z
	y1 -= z
	ans -= 2 * min(x2, y3)
	print(ans)


import sys

def pair(a, b):
	m = min(a, b)
	return (a - m, b - m)
numCases = int(input())
for x in range(numCases):
	maxScore = 0
	line1 = input()
	line2 = input()
	line1 = line1.strip()
	line2 = line2.strip()
	ints_1 = line1.split(' ')
	ints_2 = line2.split(' ')
	(x_1, y_1, z_1) = [int(x) for x in ints_1[0:3]]
	(x_2, y_2, z_2) = [int(x) for x in ints_2[0:3]]
	m = min(z_1, y_2)
	maxScore = 2 * m
	(z_1, y_2) = pair(z_1, y_2)
	(x_1, z_2) = pair(x_1, z_2)
	(z_1, z_2) = pair(z_1, z_2)
	maxScore -= z_2 * 2
	print(maxScore)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	sum = 0
	sum += min(c, e) * 2
	sub = min(c, e)
	c -= sub
	e -= sub
	sub = min(f, c)
	c -= sub
	f -= sub
	sub = min(d, c)
	c -= sub
	d -= sub
	sub = min(b, d)
	b -= sub
	d -= sub
	sub = min(b, e)
	b -= sub
	e -= sub
	sub = min(b, f)
	sum += sub * -2
	print(sum)


def main():
	for _ in range(int(input())):
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		x = min(a[2], b[1])
		a[2] -= x
		b[1] -= x
		ans = 2 * (x - max(0, b[2] - a[2] - a[0]))
		print(ans)
main()


u = int(input())
lis = []
for i in range(u):
	(na0, na1, na2) = map(int, input().split())
	(nb0, nb1, nb2) = map(int, input().split())
	if nb0 >= na1:
		if nb1 >= na2:
			lis.append(na2 * 2)
		else:
			lis.append(nb1 * 2)
	elif na1 - nb0 > nb1:
		d = na1 - nb0 - nb1
		if nb2 >= d:
			lis.append(-2 * d)
		else:
			lis.append(0)
	elif na1 - nb0 == nb1:
		lis.append(0)
	elif na2 != 0:
		e = nb1 - (na1 - nb0)
		if e >= na2:
			lis.append(na2 * 2)
		else:
			lis.append(e * 2)
	else:
		lis.append(0)
for i in lis:
	print(i)


T = int(input())
for t in range(T):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	m1 = min(z1, y2)
	ans += 2 * m1
	z1 -= m1
	y2 -= m1
	m2 = min(z1, z2)
	z1 -= m2
	z2 -= m2
	m3 = min(z1, x2)
	z1 -= m3
	x2 -= m3
	m4 = min(x1, z2)
	x1 -= m4
	z2 -= m4
	ans -= 2 * z2
	print(ans)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	if b[1] > a[2]:
		ans = a[2]
		b[1] -= a[2]
		a[2] = 0
	else:
		ans = b[1]
		a[2] -= b[1]
		b[1] = 0
	if a[0] + a[2] > b[2]:
		pass
	else:
		ans += -1 * (b[2] - (a[0] + a[2]))
	print(ans * 2)


from sys import stdin, stdout
from collections import defaultdict
import math
input = stdin.readline
for _ in range(int(input())):
	(z1, y1, x1) = map(int, input().split())
	(z2, y2, x2) = map(int, input().split())
	ans = 0
	if x1 <= y2:
		ans += 2 * x1
		y2 -= x1
		y1 -= y2 + z2
		if y1 > 0:
			ans -= y1 * 2
	else:
		ans += 2 * y2
		x1 -= y2
		if x1 < x2:
			x2 -= x1
			y1 -= z2
			if y1 > 0:
				ans -= y1 * 2
	print(ans)


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


t = int(input())
for _ in range(t):
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	min21 = min(al[2], bl[1])
	ans = 2 * min21
	al[2] -= min21
	bl[1] -= min21
	if bl[2] <= al[0] + al[2]:
		print(ans)
	else:
		rem = bl[2] - al[0] - al[2]
		ans -= 2 * rem
		print(ans)


cases = int(input())
answers = [0] * cases
for i in range(cases):
	(a, b, c) = input().split()
	(a0, a1, a2) = (int(a), int(b), int(c))
	(a, b, c) = input().split()
	(b0, b1, b2) = (int(a), int(b), int(c))
	if a2 <= b1:
		answers[i] += a2 * 2
		b1 -= a2
		a2 = 0
	else:
		answers[i] += b1 * 2
		a2 -= b1
		b1 = 0
	temp = min(a1, b0)
	a1 -= temp
	b0 -= temp
	temp = min(a0, b2)
	a0 -= temp
	b2 -= temp
	if b2 <= a0:
		a0 -= b2
		b2 = 0
	else:
		b2 -= a0
		a0 = 0
	if b2 <= a2:
		a2 -= b2
		b2 = 0
	else:
		b2 -= a2
		a2 = 0
	answers[i] -= min(a1, b2) * 2
for i in range(cases):
	print(answers[i])


import math
t = int(input())
for p in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	if c > y and z > a:
		print(2 * y - 2 * max(0, z - a - (c - y)))
	elif c <= y and z > a:
		print(2 * c - 2 * (z - a))
	elif c > y and z <= a:
		print(2 * y)
	else:
		print(2 * c)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	y = min(a[2], b[1])
	x += y * 2
	a[2] = a[2] - y
	b[1] = b[1] - y
	if a[2] == 0 and a[1] > b[1] + b[0]:
		a[1] = a[1] - b[1] - b[0]
		y = min(a[1], b[2])
		a[1] = a[1] - y
		b[2] = b[2] - y
		x -= y * 2
	if b[1] == 0 and b[2] > a[2] + a[0]:
		b[2] = b[2] - a[2] - a[0]
		y = min(b[2], a[1])
		a[1] = a[1] - y
		b[2] = b[2] - y
		x -= y * 2
	print(x)


for _ in range(int(input())):
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	f = B[2] - min(A[0], B[2])
	A[2] = A[2] - f
	t = min(A[2], B[1])
	print(2 * t)


t = int(input())
for i in range(t):
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	sum = 0
	if A[2] >= B[1]:
		sum = sum + B[1] * 2
		A[2] = A[2] - B[1]
		B[1] = 0
	else:
		sum = sum + A[2] * 2
		B[1] = B[1] - A[2]
		A[2] = 0
	if A[1] >= B[1]:
		A[1] = A[1] - B[1]
		B[1] = 0
	else:
		B[1] = B[1] - A[1]
		A[1] = 0
	if A[1] >= B[0]:
		A[1] = A[1] - B[0]
		B[0] = 0
	else:
		B[0] = B[0] - A[1]
		A[1] = 0
	if A[1] > 0:
		sum = sum - A[1] * 2
	print(sum)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	(x1, y1, z1) = I()
	(x2, y2, z2) = I()
	x = min(z1, y2)
	z1 -= x
	y2 -= x
	ans = x * 2
	z2 -= min(z2, x1 + z1)
	print(ans - z2 * 2)


def readA():
	return list(map(int, input().split()))

def intPut():
	return int(input())

def arrIt(arr, n):
	result = 0
	for i in arr:
		result += i
	return result

def solve(x1, y1, z1, x2, y2, z2):
	result = min(z1, y2) * 2
	if z1 - y2 >= 0:
		z1 = z1 - y2
		y2 = 0
		if z1 - z2 == 0 or z2 - (z1 + x1) <= 0:
			return result
		elif z2 - (z1 + x1) > 0:
			return result - 2 * abs(z2 - (z1 + x1))
		else:
			return result
	else:
		z1 = 0
		y2 = abs(z1 - y2)
		if z1 - z2 == 0 or z2 - (z1 + x1) <= 0:
			return result
		elif z2 - (z1 + x1) > 0:
			return result - 2 * abs(z2 - (z1 + x1))
		else:
			return result
	return result
for _ in range(intPut()):
	(x1, y1, z1) = readA()
	(x2, y2, z2) = readA()
	print(solve(x1, y1, z1, x2, y2, z2))


import sys
for i in range(0, int(sys.stdin.readline())):
	acount = list(map(int, sys.stdin.readline().split()))
	bcount = list(map(int, sys.stdin.readline().split()))
	twoonepairs = min(acount[2], bcount[1])
	acount[2] -= twoonepairs
	bcount[1] -= twoonepairs
	out = 2 * twoonepairs
	if bcount[2] - acount[0] - acount[2] > 0:
		out -= 2 * (bcount[2] - acount[0] - acount[2])
	sys.stdout.write(str(out) + '\n')


for case in range(int(input())):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	ans = 0
	k = min(z1, y2)
	z1 -= k
	y2 -= k
	ans += k * 2
	k = min(z1, z2)
	z1 -= k
	z2 -= k
	k = min(x1, z2)
	x1 -= k
	z2 -= k
	k = min(x1, y2)
	x1 -= k
	y2 -= k
	k = min(y1, y2)
	y1 -= k
	y2 -= k
	ans -= 2 * min(y1, z2)
	print(ans)


from collections import deque
from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(a, b) = (gil(), gil())
	ans = 2 * min(a[2], b[1])
	x = min(a[2], b[1])
	a[2] -= x
	b[1] -= x
	for y in [2, 0]:
		x = min(a[2], b[y])
		a[2] -= x
		b[y] -= x
	if a[0]:
		for y in [2, 1, 0]:
			x = min(a[0], b[y])
			b[y] -= x
			a[0] -= x
	ans -= min(a[1], b[2]) * 2
	print(ans)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from itertools import accumulate

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	for _ in range(Int()):
		a = List()
		b = List()
		s = 0
		mini = min(a[2], b[1])
		s += 2 * mini
		a[2] = a[2] - mini
		b[1] = b[1] - mini
		maxi = max(0, b[2] - a[2] - a[0])
		s -= 2 * maxi
		print(s)
solution()


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 2 * min(z1, y2)
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	if z1 == 0:
		m = min(x1, z2)
		x1 -= m
		z2 -= m
		if z2 != 0:
			ans -= 2 * min(y1, z2)
	else:
		m = min(x1, z2)
		x1 -= m
		z2 -= m
		m = min(z1, z2)
		z1 -= m
		z2 -= m
		if z2 != 0:
			ans -= 2 * min(y1, z2)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 2 * min(z1, y2)
	r = min(z1, y2)
	z1 -= r
	y2 -= r
	if z2:
		r = min(z2, z1)
		z2 -= r
		z1 -= r
		r = min(x1, z2)
		z2 -= r
		x1 -= r
		y1 -= min(y1, x2 + y2)
		ans -= 2 * min(y1, z2)
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	s = 0
	if c >= e:
		s += 2 * e
		c -= e
		f -= c
	else:
		s += 2 * c
	if f > a:
		s -= 2 * (f - a)
	print(s)


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

def mi():
	return map(int, inp().split())

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	for _ in range(ii()):
		(x1, y1, z1) = mi()
		(x2, y2, z2) = mi()
		ans = 0
		ans += 2 * min(z1, y2)
		al = max(0, min(z1, y2))
		z1 -= al
		y2 -= al
		al = max(0, min(z1, z2))
		z1 -= al
		z2 -= al
		al = max(0, min(z1, x2))
		z1 -= al
		x2 -= al
		al = max(0, min(y1, y2))
		y1 -= al
		y2 -= al
		al = max(0, min(y1, x2))
		y1 -= al
		x2 -= al
		al = max(0, min(x1, x2))
		x1 -= al
		x2 -= al
		ans -= 2 * max(0, min(y1, z2))
		print(ans)
main()


q = int(input())
while q > 0:
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	s = min(a[2], b[1]) * 2
	e = a[2] - b[1]
	c = b[2] - a[0]
	if e > 0:
		d = c - e
	else:
		d = c
	if d > 0:
		e = min(d, a[1]) * 2
		s = s - e
	print(s)
	q = q - 1


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	total = 0
	mn = min(z1, y2)
	total += 2 * mn
	z1 -= mn
	y2 -= mn
	if z1 == 0:
		mn = min(y1, y2)
		y1 -= mn
		y2 -= mn
		if y2 == 0:
			mn = min(z2, x1)
			z2 -= mn
			x1 -= mn
			if x1 == 0:
				mn = min(y1, z2)
				total -= 2 * mn
				y1 -= mn
				z2 -= mn
	else:
		mn = min(z1, z2)
		z1 -= mn
		z2 -= mn
		if z1 == 0:
			mn = min(z2, x1)
			z2 -= mn
			x1 -= mn
			if x1 == 0:
				mn = min(y1, z2)
				total -= 2 * mn
				y1 -= mn
				z2 -= mn
	print(total)


t = int(input())
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	total = 0
	low_a2b1 = min(a2, b1)
	total += low_a2b1 * 2
	a2 -= low_a2b1
	b1 -= low_a2b1
	low_a0b2 = min(a0, b2)
	a0 -= low_a0b2
	b2 -= low_a0b2
	low_a2b2 = min(a2, b2)
	a2 -= low_a2b2
	b2 -= low_a2b2
	total -= 2 * min(a1, b2)
	print(total)


def ternary(a, b):
	maxsum = 0
	common = min(a[2], b[1])
	a[2] -= common
	b[1] -= common
	maxsum += 2 * common
	common = min(a[0], b[2])
	a[0] -= common
	b[2] -= common
	common = min(a[2], b[2])
	a[2] -= common
	b[2] -= common
	common = min(a[1], b[2])
	a[1] -= common
	b[2] -= common
	maxsum -= 2 * common
	return maxsum

def takeInput(a, b, testcases):
	for i in range(testcases):
		a.append(list(map(int, input().split())))
		b.append(list(map(int, input().split())))
a = []
b = []
testcases = int(input())
takeInput(a, b, testcases)
for i in range(testcases):
	print(ternary(a[i], b[i]))


t = int(input())
for o in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b1 = []
	if a[0] < b[2]:
		b[2] -= a[0]
	else:
		a[0] -= b[2]
		b[2] = 0
	a[2] -= b[2]
	ans = 0
	if a[2] <= b[1]:
		ans += 2 * a[2]
	else:
		ans += 2 * b[1]
	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))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	m = 0
	(x0, x1, x2) = invr()
	(y0, y1, y2) = invr()
	m = min(x0, y2)
	x0 -= m
	y2 -= m
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	s = 0
	s = s + 2 * m
	s = s - 2 * min(x1, y2)
	print(s)


t = int(input())
for i in range(t):
	s = input().split(' ')
	x1 = int(s[0])
	y1 = int(s[1])
	z1 = int(s[2])
	s = input().split(' ')
	x2 = int(s[0])
	y2 = int(s[1])
	z2 = int(s[2])
	ans = int(0)
	if z1 >= y2:
		ans += 2 * y2
		z1 -= y2
		y2 = 0
	else:
		ans += 2 * z1
		z1 = 0
		y2 -= z1
	if x1 + z1 >= z2:
		ans = ans
	else:
		ans -= (z2 - (x1 + z1)) * 2
	print(ans)


T = int(input())
for t in range(T):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	k = min(a[2], b[1])
	ans += 2 * k
	a[2] -= k
	b[1] -= k
	k = min(a[1], b[0])
	a[1] -= k
	b[0] -= k
	k = min(a[0], b[2])
	a[0] -= k
	b[2] -= k
	for i in range(3):
		for j in range(i, 3):
			k = min(a[i], b[j])
			if i != j:
				ans -= k * i * j
			a[i] -= k
			b[j] -= k
	print(ans)


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
for _ in range(int(input())):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ans = 0
	x = min(l1[2], l2[1])
	ans = 2 * x
	l1[2] -= x
	l2[1] -= x
	x = min(l1[2], l2[2])
	l1[2] -= x
	l2[2] -= x
	x = min(l1[2], l2[0])
	l1[2] -= x
	l2[0] -= x
	x = min(l1[1], l2[1])
	l1[1] -= x
	l2[1] -= x
	x = min(l1[1], l2[0])
	l1[1] -= x
	l2[0] -= x
	ans -= 2 * l1[1]
	print(ans)


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) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	m = 0
	b2 -= a0
	a0 = 0
	if b2 < 0:
		a0 = -b2
		b2 = 0
	if b2 > 0:
		b2 -= a2
		a2 = 0
	if b2 < 0:
		a2 = -b2
		b2 = 0
	c = min(a1, b2)
	m -= 2 * c
	c = min(a2, b1)
	m += 2 * c
	print(m)


t = int(input())
for you in range(t):
	l = input().split()
	x1 = int(l[0])
	y1 = int(l[1])
	z1 = int(l[2])
	l = input().split()
	x2 = int(l[0])
	y2 = int(l[1])
	z2 = int(l[2])
	a = min(z1, y2)
	curr = 2 * a
	z1 -= a
	y2 -= a
	if z2 > x1 + z1:
		curr = curr - 2 * (z2 - x1 - z1)
	print(curr)


t = int(input())
for i in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	c = 0
	d = min(a2, b1)
	c = c + d * 2
	a2 = a2 - d
	b1 = b1 - d
	e = min(a1, b1)
	a1 = a1 - e
	b1 = b1 - e
	f = min(a1, b0)
	a1 = a1 - f
	b0 = b0 - f
	g = min(b2, a0)
	a0 = a0 - g
	b2 = b2 - g
	h = min(b2, a2)
	a2 = a2 - h
	b2 = b2 - h
	c = c - b2 * 2
	print(c)


for _ in range(int(input())):
	(a0, a1, a2) = [int(x) for x in input().split()]
	(b0, b1, b2) = [int(x) for x in input().split()]
	print(min(a2, b1) * 2 + (b2 > a0 + (a2 - min(a2, b1))) * min(b2 - (a0 + (a2 - min(a2, b1))), a1) * -2)


t = int(input())
while t:
	t -= 1
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	res = min(a[2], b[1])
	a[2] -= res
	b[1] -= res
	res = res * 2
	x = min(a[0] + a[2], b[2])
	b[2] -= x
	x = min(b[0] + b[1], a[1])
	a[1] -= x
	res += min(a[1], b[2]) * -2
	print(res)


def main():
	for _ in range(int(input())):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		s = 0
		s += min(z1, y2) * 2
		z1 -= min(z1, y2)
		y2 -= min(z1, y2)
		if z2 >= z1 + x1:
			s -= (z2 - (z1 + x1)) * 2
		print(s)
main()


for i in range(int(input())):
	(x1, y1, z1) = [int(num) for num in input().split()]
	(x2, y2, z2) = [int(num) for num in input().split()]
	c1 = min(z1, y2)
	z1 = z1 - c1
	c = min(x1, z2)
	z2 = z2 - c
	c3 = min(z1, z2)
	z1 = z1 - c3
	z2 = z2 - c3
	c4 = min(y1, z2)
	z2 = z2 - c4
	tot = 2 * c1 + -2 * c4
	print(tot)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		a = li()
		b = li()
		x = min(a[2], b[1])
		ans = 2 * x
		a[2] -= x
		b[1] -= x
		if a[2] > 0:
			x = min(b[2], a[2])
			a[2] -= x
			b[2] -= x
			if a[2] > 0:
				b[0] -= min(a[2], b[0])
		if a[1] > b[1] + b[0]:
			x = a[1] - b[1] - b[0]
			ans -= 2 * x
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


test = int(input())
for _ in range(test):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	p = min(z1, y2)
	z1 -= p
	y2 -= p
	ans += 2 * p
	zz = min(x1, z2)
	x1 -= zz
	z2 -= zz
	zz = min(z2, z1)
	z2 -= zz
	z1 -= zz
	if z2:
		n = min(z2, y1)
		z2 -= n
		y1 -= n
		ans -= 2 * n
	print(ans)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 0
	for i in range(3):
		j = i - 1
		t = min(a[i], b[j])
		res += i * j * t
		(a[i], b[j]) = (a[i] - t, b[j] - t)
	for i in range(3):
		j = i
		t = min(a[i], b[j])
		(a[i], b[j]) = (a[i] - t, b[j] - t)
	for i in range(3):
		j = (i + 1) % 3
		t = min(a[i], b[j])
		res -= i * j * t
		(a[i], b[j]) = (a[i] - t, b[j] - t)
	print(res)


def sol(a, b):
	ans = 2 * min(a[2], b[1])
	ab21 = min(a[2], b[1])
	a[2] -= ab21
	b[1] -= ab21
	ab11 = min(a[1], b[1])
	b[1] -= ab11
	a[1] -= ab11
	ab10 = min(a[1], b[0])
	a[1] -= ab10
	b[0] -= ab10
	ab22 = min(a[2], b[2])
	a[2] -= ab22
	b[2] -= ab22
	ab20 = min(a[0], b[2])
	b[2] -= ab20
	a[0] -= ab20
	if b[2] > 0:
		ans -= b[2] * 2
	return ans

def run():
	t = int(input())
	for i in range(t):
		inp = input().split()
		a = [int(x) for x in inp]
		inp = input().split()
		b = [int(x) for x in inp]
		print(sol(a, b))
run()


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	num = min(z, y2) * 2
	num2 = max(z2 - x - max(0, z - y2), 0) * -2
	print(num + num2)


from sys import stdin
for _ in range(int(stdin.readline())):
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	ans = 0
	k = min(a[2], b[1])
	ans += 2 * k
	a[2] -= k
	b[1] -= k
	if a[2] == 0:
		if a[1] > b[1]:
			a[1] -= b[1]
			if a[1] > b[0]:
				a[1] -= b[0]
				ans -= 2 * a[1]
	elif b[2] > a[2]:
		b[2] -= a[2]
		if b[2] > a[0]:
			b[2] -= a[0]
			ans -= 2 * b[2]
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	ans = min(z, b) * 2
	z -= min(z, b)
	b -= min(z, b)
	m = 0
	if z >= c:
		c = 0
		z = 0
	else:
		c -= z
		z = 0
		if x >= c:
			x -= c
			c = 0
		else:
			m = (c - x) * 2
			c = 0
			x = 0
	ans -= m
	print(ans)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	s = 0
	if y1 >= z:
		s += z * 2
		y1 -= z
		z = 0
	else:
		s += y1 * 2
		z -= y1
		y1 = 0
	if z1 <= x:
		x -= z1
		z1 = 0
	else:
		z1 -= x
		x = 0
	if x >= y1:
		x -= y1
		y1 = 0
	else:
		y1 -= x
		x = 0
	if x <= x1:
		x1 -= x
		x = 0
	else:
		x -= x1
		x1 = 0
	if y <= y1:
		y1 -= y
		y = 0
	else:
		y -= y1
		y1 = 0
	if y <= x1:
		x1 -= y
		y = 0
	else:
		y -= x1
		x1 = 0
	if z1 <= z:
		z -= z1
		z1 = 0
	else:
		z1 -= z
		z = 0
	if x1 <= z:
		z -= x1
		x1 = 0
	else:
		x1 -= z
		z = 0
	if z1 <= y:
		s -= z1 * 2
		y -= z1
		z1 = 0
	else:
		s -= y * 2
		z1 -= y
		y = 0
	print(s)


t = int(input())
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 0
	ans = min(a2, b1)
	if b1 > a2:
		b1 -= a2
		a2 = 0
	else:
		a2 -= b1
		b1 = 0
	if b2 > a0:
		b2 -= a0
		a0 = 0
	else:
		a0 -= b2
		b2 = 0
	if a2 >= b2:
		print(ans * 2)
	else:
		ans -= b2 - a2
		print(ans * 2)


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	nat = 0
	nat = min(a[2], b[1]) * 2
	(a[2], b[1]) = (a[2] - min(a[2], b[1]), b[1] - min(a[2], b[1]))
	(a[2], b[2]) = (a[2] - min(a[2], b[2]), b[2] - min(a[2], b[2]))
	(a[2], b[0]) = (a[2] - min(a[2], b[0]), b[0] - min(a[2], b[0]))
	(b[2], a[0]) = (b[2] - min(b[2], a[0]), a[0] - min(b[2], a[0]))
	nat -= min(b[2], a[1]) * 2
	(b[2], a[1]) = (b[2] - min(b[2], a[1]), a[1] - min(b[2], a[1]))
	print(nat)


def solve(a, b):
	ans = 0
	s = 0
	s = min(a[2], b[1])
	a[2] -= s
	b[1] -= s
	if a[2] < 0:
		a[2] = 0
	if b[1] < 0:
		b[1] = 0
	temp = min(b[2], a[2])
	a[2] -= temp
	b[2] -= temp
	if a[2] < 0:
		a[2] = 0
	if b[2] < 0:
		b[2] = 0
	temp = min(b[2], a[0])
	a[0] -= temp
	b[2] -= temp
	if a[0] < 0:
		a[0] = 0
	if b[2] < 0:
		b[2] = 0
	s2 = 0
	s2 = min(a[1], b[2])
	ans = s * 2 - s2 * 2
	return ans
for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = solve(a, b)
	print(ans)


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


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(x, y, z) = map(int, fastinput().split())
	(x1, y1, z1) = map(int, fastinput().split())
	ans = 0
	if x >= z1:
		x -= z1
		z1 = 0
		ans += 2 * min(z, y1)
		print(ans)
	else:
		z1 -= x
		if z1 >= z:
			z1 -= z
			z = 0
			print(-2 * z1)
		else:
			z -= z1
			print(2 * min(z, y1))


for _ in range(int(input())):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	sum = 0
	if z1 >= y2:
		sum = y2 * 2
		z1 = z1 - y2
		y2 = 0
		if z2 - z1 <= 0:
			print(sum)
			continue
		else:
			z2 = z2 - z1
			if z2 - x1 <= 0:
				print(sum)
				continue
			else:
				z2 = z2 - x1
				sum = sum - z2 * 2
	else:
		sum = z1 * 2
		y2 = y2 - z1
		z1 = 0
		if z2 - x1 <= 0:
			print(sum)
			continue
		else:
			z2 = z2 - x1
			sum = sum - z2 * 2
	print(sum)


for _ in range(int(input())):
	p1 = [int(i) for i in input().split()]
	p2 = [int(i) for i in input().split()]
	n = sum(p1)
	tot = []
	co = min(p1[2], p2[1])
	ans = co * 2
	p1[2] -= co
	p2[1] -= co
	if p1[0] + p1[2] < p2[2]:
		ans -= 2 * (p2[2] - p1[0] - p1[2])
	print(ans)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
t = ip()
while t:
	t -= 1
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if x1 >= z2:
		if y2 >= z1:
			print(z1 * 2)
		elif y2 != 0:
			print(y2 * 2)
		else:
			print(0)
	elif z1 == z2 - x1:
		print(0)
	elif z1 > z2 - x1:
		if y2 >= z1 - (z2 - x1):
			print(2 * (z1 - (z2 - x1)))
		elif y2 != 0:
			print(y2 * 2)
		else:
			print(0)
	else:
		print(-(2 * (z2 - x1 - z1)))


t = int(input())
ans = []
for i in range(t):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	totol = 0
	total = 2 * min(z1, y2)
	z1 -= min(z1, y2)
	if z2 > x1 + z1:
		total -= 2 * min(z2 - x1 - z1, y1)
	ans.append(total)
for i in ans:
	print(i)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve():
	pass
for i in range(int(input())):
	(a, b, c) = get_int()
	(x, y, z) = get_int()
	res = 0
	if z > 0:
		z -= a
		if z <= 0:
			a = abs(z)
			z = 0
		else:
			a = 0
	if z > 0:
		z -= c
		if z <= 0:
			c = abs(z)
			z = 0
		else:
			c = 0
	if c > 0 and y > 0:
		if c > y:
			res += 2 * y
		else:
			res += 2 * c
	print(res - 2 * z)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	plusTwo = min(a2, b1)
	covers = a2 - plusTwo + a0
	minusTwo = max(b2 - covers, 0)
	print((plusTwo - minusTwo) * 2)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	two = min(z1, y2)
	maxsum = two * 2
	y2 -= two
	z1 -= two
	if x1 + z1 >= z2:
		print(maxsum)
	else:
		x = z2 - x1 - z1
		maxsum -= x * 2
		print(maxsum)


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


T = int(input())
for t in range(T):
	[x1, y1, z1] = list(map(int, input().split()))
	[x2, y2, z2] = list(map(int, input().split()))
	s = 0
	m = min(y1, x2)
	y1 -= m
	x2 -= m
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	s += 2 * m
	s -= 2 * min(y1, z2)
	print(s)


for _ in range(int(input())):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	a = []
	b = []
	p = min(z1, y2)
	r = z2 - z1 + p - x1
	m = 0
	if r > 0:
		m = r * 2
	print(2 * p - m)


import sys
import bisect
input = sys.stdin.readline
t = int(input())

def takeSecond(elem):
	return elem[1]
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	mini1 = min(z2, x1)
	x1 -= mini1
	z2 -= mini1
	mini1 = min(z1, z2)
	z1 -= mini1
	z2 -= mini1
	mini1 = min(z2, y1)
	z2 -= mini1
	y1 -= mini1
	ans = min(y2, z1)
	print(2 * ans - 2 * mini1)


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


def reducef(z1, z2):
	x = min(z1, z2)
	return (z1 - x, z2 - x)
for _ in range(int(input())):
	[x1, y1, z1] = map(int, input().split())
	[x2, y2, z2] = map(int, input().split())
	s = 0
	if z1 > 0:
		s += 2 * min(z1, y2)
		(z1, y2) = reducef(z1, y2)
	if z1 > 0:
		(z1, z2) = reducef(z1, z2)
	if z1 > 0:
		(z1, x2) = reducef(z1, x2)
	if y1 > 0:
		(y1, y2) = reducef(y1, y2)
	if y1 > 0:
		(y1, x2) = reducef(y1, x2)
	if y1 > 0:
		s -= 2 * min(y1, z2)
		(y1, z2) = reducef(y1, z2)
	if x1 > 0:
		(x1, y2) = reducef(x1, y2)
	if x1 > 0:
		(x1, z2) = reducef(x1, z2)
	if x1 > 0:
		(x1, x2) = reducef(x1, x2)
	if x1 + y1 + z1 > 0:
		raise 'first tuple is not consumed'
	if x2 + y2 + z2 > 0:
		raise 'second tuple is not consumed'
	print(s)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	(x1, y1, z1) = MI()
	(x2, y2, z2) = MI()
	c2 = min(z1, y2)
	z1 -= c2
	y2 -= c2
	zero = min(x1 + z1, z2)
	z2 -= zero
	ans = 2 * (c2 - z2)
	print(ans)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	a = min(y2, z1)
	c1 = a * 2
	y2 -= a
	z1 -= a
	b = min(x1, z2)
	x1 -= b
	z2 -= b
	d = min(z1, z2)
	z1 -= d
	z2 -= d
	c = min(y1, z2)
	c2 = 2 * c
	print(c1 - c2)


n = int(input(''))
arr1 = []
arr2 = []
for i in range(n):
	arr1.append(list(map(int, input().split())))
	arr2.append(list(map(int, input().split())))
for i in range(n):
	t1 = arr1[i]
	t2 = arr2[i]
	[x1, y1, z1] = t1
	[x2, y2, z2] = t2
	s = 0
	u2 = min(z1, y2)
	s += u2 * 2
	if u2 == z1:
		u22 = min(z2, x1)
		if u22 == x1:
			s -= min(z2 - u22, y1) * 2
	else:
		l2 = z1 - u2
		u2 = min(l2, z2)
		if u2 == l2:
			u0 = min(x1, z2 - u2)
			if u0 == x1:
				s -= (z2 - u2 - u0) * 2
	print(s)


import sys
import math
import heapq
import collections
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def printspace(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer(' ')

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(x1, y1, z1) = inputnums()
	(x2, y2, z2) = inputnums()
	ans = 2 * min(z1, y2)
	z1 -= min(z1, y2)
	y2 -= min(z1, y2)
	if z2 - x1 - z1 > 0:
		ans -= 2 * (z2 - x1 - z1)
	print(ans)


x = int(input())
for _ in range(x):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	r = 0
	t = min(a2, b1)
	r += t * 2
	(a2, b1) = (a2 - t, b1 - t)
	t = min(a0, b2)
	(a0, b2) = (a0 - t, b2 - t)
	t = min(a2, b2)
	(a2, b2) = (a2 - t, b2 - t)
	r -= b2 * 2
	print(r)


n = int(input())
for i in range(n):
	(a0, a1, a2) = [int(x) for x in input().split()]
	(b0, b1, b2) = [int(x) for x in input().split()]
	pairs2 = min(a2, b1)
	add = 2 * pairs2
	a2 = a2 - pairs2
	b1 = b1 - pairs2
	pairs0 = min(a0, b2)
	a0 = a0 - pairs0
	b2 = b2 - pairs0
	if b2 != 0:
		negp = min(a2, b2)
		a2 -= negp
		b2 -= negp
	if b2 != 0:
		add = add - b2 * 2
	print(add)


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)))


t = int(input())
while t > 0:
	kq = 0
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	kq += min(c, y) * 2
	c -= min(y, c)
	z -= min(c, z)
	kq -= max(z - a, 0) * 2
	print(kq)
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	print(min(z, b, z + x - c) * 2)


from math import log2, ceil, floor
from collections import defaultdict, OrderedDict, Counter, deque
from heapq import heappush, heappop, heapify, nlargest, nsmallest
import re

def inp():
	return input()

def list_inp():
	return list(map(int, input().split()))

def map_inp():
	return map(int, input().split())

def int_inp():
	return int(input())

def float_int():
	return float(input())

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for _ in range(int_inp()):
	(x1, y1, z1) = map_inp()
	(x2, y2, z2) = map_inp()
	z2new = z2 - x1
	if z2new > 0:
		z1new = z1 - z2new
		z2new -= z1
		if z2new > 0:
			print(min(z2new, y1) * -2)
		else:
			print(min(y2, z1new) * 2)
	else:
		print(min(z1, y2) * 2)


import sys
from math import gcd, ceil, sqrt, ceil
from math import gcd, ceil, floor, sqrt, copysign, factorial, fmod, fsum, degrees
from math import expm1, exp, log, log2, acos, asin, cos, tan, sin, pi, e, tau, inf, nan, atan2
INF = float('inf')
MOD = 998244353
mod = 10 ** 9 + 7
from collections import Counter, defaultdict as df
from functools import reduce

def counter(l):
	return dict(Counter(l))

def printm(l):
	for i in range(len(l[0])):
		print(*l[i])

def P(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def lcm(a, b):
	return int(a * b / gcd(a, b))

def so(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def rev(l):
	return list(reversed(l))

def ini():
	return int(sys.stdin.readline())

def inp():
	return map(int, sys.stdin.readline().strip().split())

def li():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()

def inputm(n, m):
	return [li() for i in range(n)]

def c(n):
	cnt = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				cnt = cnt + 1
			else:
				cnt = cnt + 2
	return cnt

def gcdl(denominators):
	return int(reduce(lambda a, b: gcd(a, b), denominators))

def solve():
	(a1, a2, a3) = inp()
	(b1, b2, b3) = inp()
	x = min(a3, b2) * 2
	if b2 >= a3:
		b2 -= a3
	else:
		b2 = 0
	if b1 + b2 >= a2:
		print(x)
	else:
		print(x - 2 * (a2 - (b1 + b2)))
for i in range(ini()):
	solve()


def proc(u, v):
	t = min(u, v)
	u -= t
	v -= t
	return (u, v, t)
for _ in range(int(input())):
	(a0, a1, a2) = [int(x) for x in input().split()]
	(b0, b1, b2) = [int(x) for x in input().split()]
	s = 0
	(a2, b1, x) = proc(a2, b1)
	s += x * 2
	(a0, b2, _) = proc(a0, b2)
	(a0, b1, _) = proc(a0, b1)
	(a0, b0, _) = proc(a0, b0)
	(a1, b1, _) = proc(a1, b1)
	(a1, b0, _) = proc(a1, b0)
	(a2, b2, _) = proc(a2, b2)
	(a2, b0, _) = proc(a2, b0)
	(a1, b2, x) = proc(a1, b2)
	s -= x * 2
	print(s)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	post = min(a[2], b[1])
	a[2] -= post
	b[1] -= post
	ans += post * 2
	zero = min(b[2], a[2])
	b[2] -= zero
	a[2] -= zero
	zero = min(a[2], b[0])
	a[2] -= zero
	b[0] -= zero
	zero = min(a[1], b[1])
	a[1] -= zero
	b[1] -= zero
	zero = min(a[1], b[0])
	a[1] -= zero
	b[0] -= zero
	neg = min(a[1], b[2])
	ans -= 2 * neg
	print(ans)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	a1 = 0
	a2 = 0
	if z1 >= y2:
		a1 += y2 + y2
		z1 = z1 - y2
		if y1 >= x2:
			y1 -= x2
			z2 -= z1
			z2 -= x1
			a1 = a1 - y1 - y1
	else:
		y2 -= z1
		a1 += z1 + z1
		if y1 >= y2:
			y1 -= y2
			if y1 >= x2:
				y1 -= x2
				a1 = a1 - y1 - y1
	print(a1)


cases = int(input())
while cases:
	cases -= 1
	(zero, one, two) = map(int, input().split())
	(zero2, one2, two2) = map(int, input().split())
	ans = 0
	two_mn = min(two, one2)
	ans += two_mn * 2
	one2 -= two_mn
	two -= two_mn
	rem = two2 - (two + zero)
	ans -= max(rem, 0) * 2
	print(ans)


t = int(input())
while t:
	t -= 1
	(x1, y1, z1) = map(int, input().split(' '))
	(x2, y2, z2) = map(int, input().split(' '))
	sum = 0
	temp1 = min(z1, y2)
	z1 -= temp1
	y2 -= temp1
	sum = temp1 * 2
	temp2 = min(z2, x1)
	z2 -= temp2
	x1 -= temp2
	temp1 = min(z1, z2)
	z1 -= temp1
	z2 -= temp1
	if z2 != 0:
		if y1 != 0:
			sum -= z2 * 2
	print(sum)


from sys import stdin, stdout
from collections import Counter
from collections import defaultdict
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda : list(map(int, stdin.readline().split()))
ei = lambda : map(int, stdin.readline().split())
ip = lambda : int(stdin.readline().strip())
for i in range(ip()):
	(x1, y1, z1) = ei()
	(x2, y2, z2) = ei()
	ans = 0
	MIN = min(y2, z1)
	ans += 2 * MIN
	y2 = y2 - MIN
	z1 = z1 - MIN
	if z1 > 0:
		z2 -= z1
	o_2 = min(x1, z2)
	z2 = z2 - o_2
	x1 = x1 - o_2
	if z2 > 0:
		ans -= 2 * z2
	print(ans)


t = int(input())
lista = []
for i in range(t):
	summa = 0
	(a0, a1, a2) = [int(q) for q in input().split()]
	(b0, b1, b2) = [int(q) for q in input().split()]
	summa += 2 * min(a2, b1) + -2 * max(0, b2 - (a0 + max(0, a2 - b1)))
	lista.append(summa)
for i in lista:
	print(i)


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(x1, y1, z1) = [int(x) for x in inp().split()]
	(x2, y2, z2) = [int(x) for x in inp().split()]
	ans = 0
	ans += 2 * min(z1, y2)
	z1 -= min(z1, y2)
	y2 -= min(z1, y2)
	z2 -= min(z2, x1)
	z2 -= min(z2, z1)
	ans -= 2 * min(z2, y1)
	print(ans)


import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve(zerosA, onesA, twosA, zerosB, onesB, twosB):
	res = 0
	d = min(twosA, onesB)
	twosA -= d
	onesB -= d
	res += 2 * d
	d = min(zerosA, twosB)
	zerosA -= d
	twosB -= d
	d = min(zerosA, onesB)
	zerosA -= d
	onesB -= d
	d = min(twosA, twosB)
	twosA -= d
	twosB -= d
	d = min(onesA, onesB)
	onesA -= d
	onesB -= d
	d = min(onesA, zerosB)
	onesA -= d
	zerosB -= d
	d = min(onesA, twosB)
	onesA -= d
	twosB -= d
	res -= 2 * d
	return res
TC = int(input())
for tc in range(TC):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	res = solve(x1, y1, z1, x2, y2, z2)
	print(res)


from math import inf
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	m1 = min(z1, y2)
	m2 = min(y1, x2)
	m3 = min(x1, z2)
	z1 -= m1
	y2 -= m1
	y1 -= m2
	x2 -= m2
	x1 -= m3
	z2 -= m3
	m4 = min(z1, z2)
	m5 = min(y1, y2)
	z1 -= m4
	z2 -= m4
	ans = m1 * 2 - z2 * 2
	print(ans)


from sys import *
input = stdin.readline
for u in range(int(input())):
	l = list(map(int, input().split()))
	d = list(map(int, input().split()))
	c = 0
	m = min(l[2], d[1])
	l[2] -= m
	c = c + 2 * m
	x = min(l[2] + l[0], d[2])
	d[2] -= x
	c -= min(d[2], l[1]) * 2
	print(c)


x = int(input())
cases = []
for i in range(x):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	cases.append([a, b])
for i in cases:
	a = i[0]
	b = i[1]
	a0 = a[0]
	a1 = a[1]
	a2 = a[2]
	b0 = b[0]
	b1 = b[1]
	b2 = b[2]
	sum_1 = 0
	if a2 > 0 and b1 > 0:
		if a2 > b1:
			sum_1 = sum_1 + 2 * b1
			a2 = a2 - b1
			b1 = 0
		else:
			sum_1 = sum_1 + 2 * a2
			b1 = b1 - a2
			a2 = 0
	if b2 > 0 and a0 > 0:
		if b2 > a0:
			b2 = b2 - a0
			a0 = 0
		else:
			a0 = a0 - b2
			b2 = 0
	if a2 > 0 and b2 > 0:
		if a2 > b2:
			a2 = a2 - b2
			b2 = 0
		else:
			b2 = b2 - a2
			a2 = 0
	if a2 > 0 and b0 > 0:
		if a2 > b0:
			a2 = a2 - b0
			b0 = 0
		else:
			b0 = b0 - a2
			a2 = 0
	if b0 > 0 and a0 > 0:
		if a0 > b0:
			a0 = a0 - b0
			b0 = 0
		else:
			b0 = b0 - a0
			a0 = 0
	if a0 > 0 and b1 > 0:
		if a0 > b1:
			a0 = a0 - b1
			b1 = 0
		else:
			b1 = b1 - a0
			a0 = 0
	if a1 > 0 and b0 > 0:
		if a1 > b0:
			a1 = a1 - b0
			b0 = 0
		else:
			b0 = b0 - a1
			a1 = 0
	if a1 > 0 and b1 > 0:
		if a1 > b1:
			a1 = a1 - b1
			b1 = 0
		else:
			b1 = b1 - a1
			a1 = 0
	if b2 > 0 and a1 > 0:
		sum_1 = sum_1 - 2 * min(b2, a1)
		b2 = 0
		a1 = 0
	print(sum_1)


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	a = [int(x) for x in stdin.readline().split()]
	b = [int(x) for x in stdin.readline().split()]
	temp = min(a[2], b[1])
	a[2] -= temp
	b[1] -= temp
	ans = 2 * temp
	temp = min(a[2], b[2])
	a[2] -= temp
	b[2] -= temp
	temp = min(a[1], b[1])
	a[1] -= temp
	b[1] -= temp
	temp = min(a[0], b[2])
	a[0] -= temp
	b[2] -= temp
	temp = min(a[1], b[0])
	a[1] -= temp
	b[0] -= temp
	temp = min(a[1], b[2])
	a[1] -= temp
	b[2] -= temp
	ans -= 2 * temp
	print(ans)


t1 = int(input())
while t1 > 0:
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mini = min(a[2], b[1])
	t = 0
	t += 2 * mini
	a[2] -= mini
	b[1] -= mini
	maxi = max(0, b[2] - a[2] - a[0])
	t -= 2 * maxi
	print(t)
	t1 -= 1


tests = int(input())
for t in range(tests):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	first = min(z1, y2) * 2
	r_1 = max(z1 - min(z1, y2), 0)
	second = min(z2, x1)
	r_2 = max(z2 - min(z2, x1), 0)
	third = max(r_2 - r_1, 0) * 2
	res = first - third
	print(res)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	s = min(z1, y2) * 2
	z1 -= min(z1, y2)
	if z2 > x1:
		i = min(y1, z2 - x1 - z1)
		if i < 0:
			i = 0
		sum = s - 2 * i
	else:
		sum = s
	print(sum)


t = int(input())
while t:
	(x, y, z) = input().split()
	(a, b, c) = input().split()
	(x, y, z) = (int(x), int(y), int(z))
	(a, b, c) = (int(a), int(b), int(c))
	s = 0
	s = s + 2 * min(z, b)
	if c > x + max(0, z - b):
		c = c - (x + max(0, z - b))
		s = s - 2 * min(c, y)
	print(s)
	t = t - 1


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline

def calc(a, b):
	first = a[:]
	second = b[:]
	bf = min(first[1], second[-1])
	first[1] -= bf
	bf = min(second[0], first[-1])
	second[0] -= bf
	res = min(first[0], second[1]) * 2 - min(second[0], first[1]) * 2
	return res
for _ in range(int(input())):
	first = list(map(int, input().split()))
	second = list(map(int, input().split()))
	print(calc(first[::-1], second[::-1]))


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)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		(x, y, z) = inar()
		(xx, yy, zz) = inar()
		ans = 0
		ans += min(z, yy) * 2
		take = min(z, yy)
		z -= take
		yy -= take
		if x + z >= zz:
			print(ans)
		else:
			zz -= x + z
			ans -= zz * 2
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, os

def solve():
	arr = [int(i) for i in input().split()]
	arr1 = [int(i) for i in input().split()]
	a = arr[0]
	b = arr[1]
	c = arr[2]
	a1 = arr1[0]
	b1 = arr1[1]
	c1 = arr1[2]
	profit = min(c, b1)
	c -= profit
	b1 -= profit
	profit = 2 * profit
	diff1 = min(b, a1)
	b -= diff1
	a1 -= diff1
	diff2 = min(c, a1)
	c -= diff2
	a1 -= diff2
	diff2 = min(c, c1)
	c -= diff2
	c1 -= diff2
	diff1 = min(b, b1)
	b -= diff1
	b1 -= diff1
	profit -= 2 * min(b, c1)
	print(profit)
test = int(input())
while test:
	solve()
	test -= 1


import sys
input = sys.stdin.readline

def solve():
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a[2], b[1])
	ans = 2 * c
	a[2] -= c
	b[1] -= c
	c = min(a[0], b[2])
	a[0] -= c
	b[2] -= c
	c = min(a[2], b[2])
	a[2] -= c
	b[2] -= c
	ans -= 2 * b[2]
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
while t:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	k = min(z1, y2)
	ans = k * 2
	z1 -= k
	y2 -= k
	k = min(z2, x1)
	z2 -= k
	x1 -= k
	k = min(z1, z2)
	z1 -= k
	z2 -= k
	k = min(z2, y1)
	ans -= k * 2
	print(ans)
	t -= 1


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


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


t = int(input())
ans = ''
for _ in range(t):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	A = min(a[2], b[1])
	B = max(0, b[2] - a[2] - a[0] + A)
	ans += str(2 * (A - B)) + '\n'
print(ans)


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


t = int(input())
for abc in range(t):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	z -= a
	cnt = 0
	if c >= y:
		cnt += 2 * y
		c -= y
		z -= c
	else:
		cnt += 2 * c
	if z <= 0:
		print(cnt)
	else:
		cnt -= z * 2
		print(cnt)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a[2], b[1])
	a[2] -= x
	b[1] -= x
	y = min(a[1], b[0] + b[1])
	print(2 * x - 2 * (a[1] - y))


def resolve():
	loop_n = int(input())
	for _ in range(loop_n):
		A = [int(x) for x in input().split(' ')]
		B = [int(x) for x in input().split(' ')]
		ans = 0
		if A[2] >= B[1]:
			ans += 2 * B[1]
			A[2] -= B[1]
			B[1] = 0
		else:
			ans += 2 * A[2]
			A[2] = 0
			B[1] -= A[2]
		if B[2] >= A[0]:
			B[2] -= A[0]
			A[0] = 0
		else:
			A[0] -= B[2]
			B[2] = 0
		if B[2] >= A[2]:
			B[2] -= A[2]
			A[2] = 0
		else:
			A[2] -= B[2]
			B[2] = 0
		ans -= 2 * B[2]
		print(ans)
resolve()


for _ in range(int(input())):
	max = 0
	(ax, ay, az) = map(int, input().split())
	(bx, by, bz) = map(int, input().split())
	if az > by:
		max += 2 * by
		az -= by
	else:
		max += 2 * az
		az = 0
	if bz > ax + az:
		max -= 2 * (bz - ax - az)
	print(max)


t = int(input())
for _ in range(t):
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	positive = min(l1[2], l2[1]) * 2
	pad = 0
	if l1[2] > l2[1]:
		pad += l1[2] - l2[1]
	negative = 2 * (l2[2] - l1[0] - pad)
	print(positive - max(0, negative))


t = int(input())
while t > 0:
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 0
	minn = min(c, y)
	ans += minn * 2
	c -= minn
	y -= minn
	maxx = max(0, z - a - c)
	ans -= maxx * 2
	print(ans)
	t -= 1


for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	val = min(a[2], b[1])
	count += 2 * val
	a[2] -= val
	b[1] -= val
	val = min(a[0] + a[2], b[2])
	b[2] -= val
	count -= 2 * b[2]
	print(count)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	num_pos = min(z1, y2)
	if y2 > z1:
		left_ones = y2 - z1
	else:
		left_ones = 0
	num_neg = max(y1 - left_ones - x2, 0)
	print(num_pos * 2 - num_neg * 2)


for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sm = 0
	miner = min(z1, y2)
	z1 = z1 - miner
	y2 = y2 - miner
	sm += 2 * miner
	y1 = y1 - (y2 + x2)
	if y1 > 0:
		sm -= 2 * min(y1, z2)
	print(sm)


I = input

def main():
	for _ in range(int(I())):
		a = list(map(int, I().split()))
		b = list(map(int, I().split()))
		sum = 0
		if a[2] and b[1]:
			m = min(a[2], b[1])
			a[2] -= m
			b[1] -= m
			sum += m * 2
		for i in range(2, -1, -1):
			for j in range(i, -1, -1):
				if a[i] and b[j]:
					m = min(a[i], b[j])
					a[i] -= m
					b[j] -= m
		if a[1] and b[2]:
			m = min(a[1], b[2])
			a[1] -= m
			b[2] -= m
			sum -= m * 2
		print(sum)
main()


import sys

def Ints():
	return map(int, sys.stdin.readline().strip().split())

def Strs():
	return map(str, sys.stdin.readline().strip().split())

def Array():
	return list(map(int, sys.stdin.readline().strip().split()))

def Str():
	return sys.stdin.readline().strip()

def Int():
	return int(sys.stdin.readline().strip())

def MOD():
	return 1000000007
n = Int()
for i in range(n):
	(a0, a1, a2) = Ints()
	(b0, b1, b2) = Ints()
	total = 0
	if a2 != 0 and b1 != 0:
		value = min(a2, b1)
		total += 2 * value
		a2 -= value
		b1 -= value
	if a2 != 0 and b2 != 0:
		value = min(a2, b2)
		a2 -= value
		b2 -= value
	if a1 != 0 and b1 != 0:
		value = min(a1, b1)
		a1 -= value
		b1 -= value
	if a0 != 0 and b2 != 0:
		value = min(a0, b2)
		a0 -= value
		b2 -= value
	if a1 != 0 and b0 != 0:
		value = min(a1, b0)
		a1 -= value
		b0 -= value
	if a1 != 0 and b2 != 0:
		value = min(a1, b2)
		total -= 2 * value
		a1 -= value
		b2 -= value
	print(total)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(a, b, c) = cin()
	(p, q, r) = cin()
	k = min(c, q)
	ans = k * 2
	c = c - k
	q = q - k
	k1 = min(b, p)
	b = b - k1
	p = p - k1
	k2 = min(b, q)
	b = b - k2
	q = q - k2
	k3 = min(c, r)
	c = c - k3
	r = r - k3
	k4 = min(a, r)
	a = a - k4
	r = r - k4
	if b > 0 and r > 0:
		ans -= 2 * min(b, r)
	print(ans)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	mini = min(z1, y2)
	z1 -= mini
	y2 -= mini
	ans += 2 * mini
	mini2 = min(z1, z2)
	z1 -= mini2
	z2 -= mini2
	mini3 = min(x1, z2)
	x1 -= mini3
	z2 -= mini3
	mini4 = min(z2, y1)
	ans -= 2 * mini4
	print(ans)


from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	(a, b, c) = M()
	(d, e, f) = M()
	g = min(a, f)
	f -= g
	a -= g
	g = min(c, f)
	f -= g
	c -= g
	ans = min(c, e) * 2
	g = min(c, e)
	c -= g
	e -= g
	g = min(e, a)
	e -= g
	a -= g
	g = min(e, b)
	e -= g
	b -= g
	print(ans + f * -2 + e * -1)


import math
t = int(input())
while t > 0:
	t -= 1
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	v = min(a[0], b[2])
	a[0] -= v
	b[2] -= v
	v = min(a[0], b[0])
	a[0] -= v
	b[0] -= v
	v = min(b[0], a[1])
	a[1] -= v
	b[0] -= v
	v = min(a[2], b[2])
	a[2] -= v
	b[2] -= v
	v = min(a[1], b[1])
	a[1] -= v
	b[1] -= v
	v = min(b[1], a[0])
	a[0] -= v
	b[1] -= v
	v = min(b[0], a[2])
	a[2] -= v
	b[0] -= v
	s = -1 * (2 * b[2])
	s += 2 * a[2]
	print(s)


t = int(input())
while t > 0:
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	total = 0
	m = min(x0, y2)
	y2 -= m
	m = min(x1, y0)
	x1 -= m
	m = min(x2, y1)
	total += 2 * m
	total -= 2 * min(x1, y2)
	print(total)
	t = t - 1


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	(x, y, z) = ria()
	(a, b, c) = ria()
	k = min(z, b)
	cnt = 2 * k
	z -= k
	b -= k
	if z != 0:
		k = min(z, c)
		z -= k
		c -= k
	if z != 0:
		k = min(z, a)
		z -= k
		c -= k
	k = min(y, b)
	y -= k
	b -= k
	if y != 0:
		k = min(y, a)
		y -= k
		a -= k
	if y != 0:
		k = min(y, c)
		cnt = cnt - 2 * k
		y -= k
		c -= k
	print(cnt)


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


r = int(input())
a = []
for i in range(r):
	(x1, y1, z1) = str(input()).split()
	(x2, y2, z2) = str(input()).split()
	(x1, y1, z1) = (int(x1), int(y1), int(z1))
	(x2, y2, z2) = (int(x2), int(y2), int(z2))
	k = 0
	if z1 > 0:
		k += 2 * min(z1, y2)
		t = min(z1, y2)
		z1 -= t
		y2 -= t
	if z1 > 0:
		t = min(z1, z2)
		z1 -= t
		z2 -= t
	if z1 > 0:
		t = min(z1, x2)
		z1 -= t
		x2 -= t
	if y1 > 0:
		t = min(y1, y2)
		y1 -= t
		y2 -= t
	if y1 > 0:
		t = min(y1, x2)
		y1 -= t
		x2 -= t
	if y1 > 0:
		k -= 2 * min(y1, z2)
		t = min(y1, z2)
		y1 -= t
		z2 -= t
	a.append(k)
for u in range(len(a)):
	print(a[u])


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = map(int, input().split())
	s = 0
	x = min(a, c1)
	a -= x
	c1 -= x
	y = min(b, a1)
	b -= y
	a1 -= y
	z = min(c, b1)
	c -= z
	b1 -= z
	s = s + 2 * z
	s -= 2 * min(b, c1)
	print(s)


def solve(n0, n1, n2, m0, m1, m2):
	n2m1 = min(n2, m1)
	n2 -= n2m1
	m1 -= n2m1
	n2m2 = min(n2, m2)
	n2 -= n2m2
	m2 -= n2m2
	n2m0 = min(n2, m0)
	n2 -= n2m0
	m0 -= n2m0
	n1m1 = min(n1, m1)
	n1 -= n1m1
	m1 -= n1m1
	n1m0 = min(n1, m0)
	n1 -= n1m0
	m0 -= n1m0
	n0m2 = min(n0, m2)
	n0 -= n0m2
	m2 -= n0m2
	n0m1 = min(n0, m1)
	n0 -= n0m1
	m1 -= n0m1
	n0m0 = min(n0, m0)
	n0 -= n0m0
	m0 -= n0m0
	return 2 * (n2m1 - min(n1, m2))
t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	print(solve(x1, y1, z1, x2, y2, z2))


t = int(input())
for _ in range(t):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	o = 0
	if z1 > y2:
		z1 -= y2
		o += y2 * 2
		y2 = 0
	else:
		y2 -= z1
		o += z1 * 2
		z1 = 0
	s = z2 - x1 - z1
	if s > 0:
		o -= s * 2
	print(o)


for _ in range(int(input())):
	(x, y, z) = list(map(int, input().split()))
	(a, b, c) = list(map(int, input().split()))
	suma = 0
	p = min(z, b)
	suma += 2 * p
	z -= p
	b -= p
	if z != 0:
		p = min(z, c)
		z -= p
		c -= p
	p = min(y, a)
	y -= p
	a -= p
	if y != 0:
		p = min(y, b)
		y -= p
		b -= p
	p = min(x, c)
	x -= p
	c -= p
	if x != 0:
		p = min(x, a)
		x -= p
		a -= p
	if y != 0 and c != 0:
		p = min(y, c)
		suma -= 2 * p
	print(suma)


t = int(input())
while t > 0:
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	m21 = min(li1[2], li2[1])
	sum = m21 * 2
	li1[2] -= m21
	li2[1] -= m21
	m02 = min(li1[0], li2[2])
	li2[2] -= m02
	li1[0] -= m02
	m22 = min(li1[2], li2[2])
	li1[2] -= m22
	li2[2] -= m22
	m12 = min(li1[1], li2[2])
	sum -= 2 * m12
	print(sum)
	t -= 1
	pass


for t in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	opa = [2, 1, 1, 0, 2, 1]
	opb = [1, 0, 1, 2, 2, 2]
	res = 0
	for i in range(6):
		if a[opa[i]] < b[opb[i]]:
			c = a[opa[i]]
			a[opa[i]] -= c
			b[opb[i]] -= c
			if i == 0:
				res += c * 2
			elif i == 5:
				res -= c * 2
		else:
			c = b[opb[i]]
			a[opa[i]] -= c
			b[opb[i]] -= c
			if i == 0:
				res += c * 2
			elif i == 5:
				res -= c * 2
	print(res)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		A_Vals = [int(i) for i in stdin.readline().split()]
		B_Vals = [int(i) for i in stdin.readline().split()]
		total = 0
		order = [(2, 1), (2, 2), (0, 2), (1, 1), (1, 0), (0, 0), (2, 0), (0, 1), (1, 2)]
		for o in order:
			count = min(A_Vals[o[0]], B_Vals[o[1]])
			A_Vals[o[0]] -= count
			B_Vals[o[1]] -= count
			if o == (2, 1):
				total += count * 2
			elif o == (1, 2):
				total -= count * 2
		stdout.write('{0}\n'.format(total))
main()


t = int(input())
for i in range(t):
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	two_ones = min(a[2], b[1])
	b[1] -= two_ones
	a[2] -= two_ones
	zero_twos = min(a[0], b[2])
	a[0] -= zero_twos
	b[2] -= zero_twos
	two_twos = min(a[2], b[2])
	a[2] -= two_twos
	b[2] -= two_twos
	one_twos = min(a[1], b[2])
	print(2 * (two_ones - one_twos))


test = int(input())
for tes in range(test):
	(l1, m1, n1) = list(map(int, input().split()))
	(l2, m2, n2) = list(map(int, input().split()))
	sum = 0
	if n1 > m2:
		n1 -= m2
		sum += 2 * m2
		m2 = 0
	else:
		m2 -= n1
		sum += 2 * n1
		n1 = 0
	if n1 > l2:
		n1 -= l1
		l1 = 0
	else:
		l1 -= n1
		n1 = 0
	if m1 > l2:
		m1 -= l2
		l2 = 0
	else:
		l2 -= m1
		m1 = 0
	if n1 > n2:
		n1 -= n2
		n2 = 0
	else:
		n2 -= n1
		n1 = 0
	if m1 > m2:
		m1 -= m2
		m2 = 0
	else:
		m2 -= m1
		m1 = 0
	if n2 > l1:
		n2 -= l1
		l1 = 0
	else:
		l1 -= n2
		n2 = 0
	if m1 > n2:
		m1 -= n2
		sum -= 2 * n2
		n2 = 0
	else:
		n2 -= m1
		sum -= 2 * m1
		m1 = 0
	print(sum)


for i in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = int(0)
	ans += min(a2, b1) * 2
	(a2, b1) = (a2 - min(a2, b1), b1 - min(a2, b1))
	(a2, b2) = (a2 - min(a2, b2), b2 - min(a2, b2))
	(a1, b1) = (a1 - min(a1, b1), b1 - min(a1, b1))
	(a0, b2) = (a0 - min(a0, b2), b2 - min(a0, b2))
	(b0, a1) = (b0 - min(b0, a1), a1 - min(b0, a1))
	ans -= min(a1, b2) * 2
	print(ans)


import sys, math as mt
import heapq as hp
import collections as cc
import math as mt
import itertools as it
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(a, b, c) = I()
	(aa, bb, cc) = I()
	temp = min(c, bb)
	bb -= temp
	c -= temp
	ans = temp * 2
	if c + a < cc:
		ans -= (cc - c - a) * 2
	print(ans)


T = int(input())
for t in range(T):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	tmp = min(x2, y1)
	tot = 2 * tmp
	x2 -= tmp
	y1 -= tmp
	tmp = min(x0, y2)
	x0 -= tmp
	y2 -= tmp
	tmp = min(x1, y0)
	x1 -= tmp
	y0 -= tmp
	tmp = min(x0, y1)
	x0 -= tmp
	y1 -= tmp
	tmp = min(x2, y2)
	x2 -= tmp
	y2 -= tmp
	tot -= 2 * max(0, y2 - x0)
	print(tot)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for xyz in range(0, int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 2 * min(a2, b1)
	(a2, b1) = (max(0, a2 - b1), max(0, b1 - a2))
	(b2, a2) = (max(0, b2 - a2), max(0, a2 - b2))
	(b2, a0) = (max(0, b2 - a0), max(0, a0 - b2))
	ans -= 2 * b2
	print(ans)


t = int(input())
for case in range(0, t):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	res = 0
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	res += 2 * m
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(y1, x2)
	y1 -= m
	x2 -= m
	res -= 2 * min(y1, z2)
	print(res)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	_2_1_count = min(z1, y2)
	z1 -= _2_1_count
	y2 -= _2_1_count
	_2_2_count = min(z1, z2)
	z1 -= _2_2_count
	z2 -= _2_2_count
	_0_2_count = min(x1, z2)
	x1 -= _0_2_count
	z2 -= _0_2_count
	_1_2_count = min(y1, z2)
	print(_2_1_count * 2 - _1_2_count * 2)


t = int(input())
for i in range(t):
	(z, f, s) = map(int, input().split())
	(z2, f2, s2) = map(int, input().split())
	ans = 0
	mi = min(s2, z)
	s2 -= mi
	z -= mi
	if s2 != 0:
		mi = min(s, s2)
		s -= mi
		s2 -= mi
	ans += min(s, f2) * 2
	ans -= min(s2, f) * 2
	print(ans)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	summ = 0
	temp = min(z1, y2)
	z1 -= temp
	y2 -= temp
	summ += temp * 2
	temp = min(y1, x2)
	y1 -= temp
	x2 -= temp
	temp = min(y1, y2)
	y1 -= temp
	y2 -= temp
	temp = min(x1, z1)
	x1 -= temp
	z1 -= temp
	temp = min(y1, z2)
	y1 -= temp
	z2 -= temp
	summ -= 2 * temp
	print(summ)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	if a[2] > 0 and b[1] > 0:
		k = min(a[2], b[1])
		s = 2 * k
		a[2] -= k
		b[1] -= k
	if a[2] > 0 and b[2] > 0:
		k = min(a[2], b[2])
		a[2] -= k
		b[2] -= k
	if a[2] > 0 and b[1] > 0:
		k = min(a[2], b[1])
		a[2] -= k
		b[2] -= k
	if b[2] > 0 and a[0] > 0:
		k = min(b[2], a[0])
		b[2] -= k
		a[0] -= k
	if a[1] > 0 and b[1] > 0:
		k = min(a[1], b[1])
		a[1] -= k
		b[1] -= k
	if a[1] > 0 and b[0] > 0:
		k = min(a[1], b[0])
		a[1] -= k
		b[1] -= k
	if a[1] > 0:
		s -= a[1] * 2
	print(s)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	tw = 0
	zr = 0
	neg = 0
	if z1 > 0:
		tp = min(z1, y2)
		z1 -= tp
		y2 -= tp
		tw += tp
	if z1 > 0:
		tp = min(z1, z2)
		z1 -= tp
		z2 -= tp
		zr += tp
	if z1 > 0:
		tp = min(z1, x2)
		z1 -= tp
		x2 -= tp
		zr += tp
	if x1 > 0:
		tp = min(x1, z2)
		x1 -= tp
		z2 -= tp
	if y1 > 0:
		tp = min(y1, y2)
		y1 -= tp
		y2 -= tp
		zr += tp
	if y1 > 0:
		tp = min(y1, x2)
		y1 -= tp
		x2 -= tp
		zr += tp
	if y1 > 0:
		tp = min(y1, z2)
		y1 -= tp
		z2 -= tp
		neg += tp
	ans = 2 * tw - 2 * neg
	print(ans)


t = int(input())
for i in range(t):
	s1 = [int(item) for item in input().split(' ')]
	s2 = [int(item) for item in input().split(' ')]
	positive = min(s1[2], s2[1])
	s1[2] -= positive
	s2[1] -= positive
	neutral = min(s1[1], sum(s2[:2]))
	s1[1] -= neutral
	diff = min(neutral, s2[0])
	s2[0] -= diff
	s2[1] -= neutral - diff
	neutral = min(sum([s1[0], s1[2]]), s2[2])
	s2[2] -= neutral
	diff = min(neutral, s2[2])
	s1[0] -= diff
	s1[2] -= neutral - diff
	negative = s1[1]
	res = 2 * (positive - negative)
	print(res)


def sol(a0, a1, a2, b0, b1, b2):
	c = 0
	if b2 != 0 and a0 != 0:
		if b2 <= a0:
			a0 -= b2
			b2 = 0
		elif b2 > a0:
			b2 -= a0
			a0 = 0
	if b2 != 0 and a2 != 0:
		if b2 <= a2:
			a2 -= b2
			b2 = 0
		elif b2 > a2:
			b2 -= a2
			a2 = 0
	if b2 != 0 and a1 != 0:
		if b2 <= a1:
			c -= 2 * b2
			a1 -= b2
			b2 = 0
		elif b2 > a1:
			c -= 2 * a1
			b2 -= a1
			a1 = 0
	if b0 != 0 and a0 != 0:
		if b0 <= a0:
			a0 -= b0
			b0 = 0
		elif b0 > a0:
			b0 -= a0
			a0 = 0
	if b0 != 0 and a1 != 0:
		if b0 <= a1:
			a1 -= b0
			b0 = 0
		elif b0 > a1:
			b0 -= a1
			a1 = 0
	if b0 != 0 and a2 != 0:
		if b0 <= a2:
			a2 -= b0
			b0 = 0
		elif b0 > a2:
			b0 -= a2
			a2 = 0
	if b1 != 0 and a2 != 0:
		if b1 <= a2:
			c += 2 * b1
			a2 -= b1
			b1 = 0
		elif b1 > a2:
			c += 2 * a2
			b1 -= a2
			a2 = 0
	return c
t = int(input())
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	print(sol(a0, a1, a2, b0, b1, b2))


t = int(input())
for _ in range(t):
	(x, y, z) = map(int, input().split())
	(xx, yy, zz) = map(int, input().split())
	c1 = min(z, yy)
	s = 2 * min(z, yy)
	z -= c1
	if zz:
		zz -= min(zz, x)
		if zz:
			zz -= min(zz, z)
	s -= 2 * zz
	print(s)


t = int(input())
for _ in range(t):
	(a_0, a_1, a_2) = [int(i) for i in input().split()]
	(b_0, b_1, b_2) = [int(i) for i in input().split()]
	ans = 0
	while a_2 > 0:
		if b_1 > 0:
			mi = min(a_2, b_1)
			a_2 -= mi
			b_1 -= mi
			ans += 2 * mi
		elif b_2 > 0:
			mi = min(a_2, b_2)
			a_2 -= mi
			b_2 -= mi
		elif b_0 > 0:
			mi = min(a_2, b_0)
			a_2 -= mi
			b_0 -= mi
	while a_0 > 0:
		if b_2 > 0:
			mi = min(a_0, b_2)
			a_0 -= mi
			b_2 -= mi
		elif b_1 > 0:
			mi = min(a_0, b_1)
			a_0 -= mi
			b_1 -= mi
		elif b_0 > 0:
			mi = min(a_0, b_0)
			a_0 -= mi
			b_0 -= mi
	while a_1 > 0:
		if b_1 > 0:
			mi = min(a_1, b_1)
			a_1 -= mi
			b_1 -= mi
		elif b_0 > 0:
			mi = min(a_1, b_0)
			a_1 -= mi
			b_0 -= mi
		elif b_2 > 0:
			mi = min(a_1, b_2)
			a_1 -= mi
			b_2 -= mi
			ans -= 2 * mi
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(a1, b1, c1) = Ri()
	(a2, b2, c2) = Ri()
	temp = min(c1, b2)
	ans = 2 * temp
	c1 -= temp
	b2 -= temp
	temp = min(c1, c2)
	c1 -= temp
	c2 -= temp
	temp = min(a1, c2)
	c2 -= temp
	a1 -= temp
	temp = min(b2, a1)
	b2 -= temp
	a1 -= temp
	temp = min(b2, b1)
	b2 -= temp
	b1 -= temp
	if c2 != 0:
		ans -= 2 * min(c2, b1)
	print(ans)


for i in range(int(input())):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	c21 = min(a[2], b[1])
	ans += 2 * c21
	a[2] -= c21
	b[1] -= c21
	c02 = min(a[0], b[2])
	a[0] -= c02
	b[2] -= c02
	c10 = min(a[1], b[0])
	a[1] -= c10
	b[0] -= c10
	c22 = min(a[2], b[2])
	a[2] -= c22
	b[2] -= c22
	c11 = min(a[1], b[1])
	a[1] -= c11
	b[1] -= c11
	ans -= min(a[1], b[2]) * 2
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	s = 2 * min(c, y)
	q = c - min(c, y)
	r = q + a
	if z > r:
		z = z - r
	else:
		z = 0
	n = -2 * min(z, b)
	print(s + n, end='\n')


t = int(input())
for _ in range(t):
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	res = min(b[1], a[2]) * 2
	r1 = min(a[0], b[2])
	r2 = min(a[1], b[0])
	res -= 2 * min(a[1] - r2, b[2] - r1)
	print(res)


ls = []
t = int(input())
for z in range(t):
	count = 0
	x = list(map(int, input().rstrip().split()))
	y = list(map(int, input().rstrip().split()))
	x2 = x[2]
	y2 = y[2]
	x1 = x[1]
	y1 = y[1]
	x0 = x[0]
	y0 = y[0]
	val2 = min(x2, y1)
	count += 2 * val2
	x2 -= val2
	y1 -= val2
	val2 = min(y2, x0)
	x0 -= val2
	y2 -= val2
	val2 = min(y2, x2)
	x2 -= val2
	y2 -= val2
	if y2 > 0:
		count -= 2 * y2
	ls.append(count)
for i in ls:
	print(i)


import sys
input = sys.stdin.readline
for n in range(int(input())):
	(x, y, z) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	ans = 0
	if x >= z1:
		x -= z1
		z1 = 0
	else:
		z1 -= x
		x = 0
	if y >= x1:
		y -= x1
		x1 = 0
	else:
		x1 -= y
		y = 0
	if z >= y1:
		z -= y1
		ans += 2 * y1
		y1 = 0
	else:
		y1 -= z
		ans += 2 * z
		z = 0
	if y >= z1:
		y -= z1
		ans += -2 * z1
	else:
		z1 -= y
		ans += -2 * y
	print(ans)


ts = int(input())
for t in range(ts):
	(x1, y1, z1) = [int(i) for i in input().split(' ')]
	(x2, y2, z2) = [int(i) for i in input().split(' ')]
	c = 0
	if z1 <= y2:
		c += 2 * z1
		if z2 > x1:
			c -= 2 * (z2 - x1)
	else:
		c += 2 * y2
		z11 = x1 + z1 - y2
		if z2 > z11:
			c -= 2 * (z2 - z11)
	print(c)


t = int(input())
for i in range(t):
	(a0, a1, a2) = [int(e) for e in input().split()]
	(b0, b1, b2) = [int(e) for e in input().split()]
	sum = 0
	sum += 2 * min(a2, b1)
	(a2, b1) = (a2 - min(a2, b1), b1 - min(a2, b1))
	(a1, b0) = (a1 - min(a1, b0), b0 - min(a1, b0))
	(a1, b1) = (a1 - min(a1, b1), b1 - min(a1, b1))
	(a0, b0) = (a0 - min(a0, b0), b0 - min(a0, b0))
	(a2, b0) = (a2 - min(a2, b0), b0 - min(a2, b0))
	(a0, b1) = (a0 - min(a0, b1), b1 - min(a0, b1))
	(a0, b2) = (a0 - min(a0, b2), b2 - min(a0, b2))
	(a2, b2) = (a2 - min(a2, b2), b2 - min(a2, b2))
	sum -= 2 * a1
	print(sum)


try:
	for i1 in range(int(input())):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		c = 0
		if y1 == 0 and y2 == 0:
			print(0)
			continue
		elif y1 == 0 and z1 == 0:
			print(0)
			continue
		else:
			if z2 <= x1:
				x1 -= z2
				z2 = 0
			else:
				z2 -= x1
				x1 = 0
				if z2 <= z1:
					z1 -= z2
					z2 = 0
				else:
					z2 -= z1
					z1 = 0
			if z2 == 0:
				if z1 != 0:
					if y2 <= z1:
						z1 -= y2
						c = c + y2 * 2
						y2 = 0
					else:
						y2 -= z1
						c += z1 * 2
						z1 = 0
				else:
					c = 0
			else:
				c -= z2 * 2
			print(c)
except:
	pass


n = int(input())
S = []
for i in range(n):
	res = 0
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	p = min(z1, y2)
	z1 -= p
	y2 -= p
	res += 2 * p
	t = min(x1, z2)
	x1 -= t
	z2 -= t
	if z2 > z1:
		res = res - 2 * (z2 - z1)
	S.append(res)
for k in S:
	print(k)


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


t = int(input())
for _ in range(t):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	n2 = min(x2, y1)
	x2 -= n2
	y1 -= n2
	remus1 = x0 + x2
	remus2 = y0 + y1
	if x1 <= remus2 or y2 <= remus1:
		print(n2 * 2)
	else:
		print(n2 * 2 - 2 * (x1 - remus2))


t = int(input())
for i in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	s = 0
	cur = min(a2, b1)
	s += 2 * cur
	a2 -= cur
	b1 -= cur
	maxi = max(0, b2 - a2 - a0)
	s -= 2 * maxi
	print(s)


for _ in range(int(input())):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	t1 = min(c1, b2)
	t2 = min(b1, a2)
	s = 0
	s = 2 * min(c1, b2)
	c1 -= t1
	b2 -= t1
	b1 -= t2
	a2 -= t2
	if c2 > a1 + c1:
		s -= 2 * (c2 - a1 - c1)
	print(s)


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(x, y, z) = map(int, stdin.readline().split())
	(X, Y, Z) = map(int, stdin.readline().split())
	ans = 0
	plus = min(z, Y)
	ans += 2 * plus
	Y -= plus
	z -= plus
	p = min(x, Z)
	x -= p
	Z -= p
	p = min(z, Z)
	Z -= p
	ans -= 2 * Z
	print(ans)


import math
t = int(input())
while t:
	X = [int(x) for x in input().split(' ')]
	Y = [int(x) for x in input().split(' ')]
	sum = 0
	diff = min(X[2], Y[1])
	sum += diff * 2
	X[2] -= diff
	Y[1] -= diff
	diff = min(X[2], Y[2])
	X[2] -= diff
	Y[2] -= diff
	diff = min(X[0], Y[2])
	X[0] -= diff
	Y[2] -= diff
	diff = min(X[1], Y[2])
	X[1] -= diff
	Y[2] -= diff
	sum -= 2 * diff
	print(sum)
	t -= 1


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


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class union_find:

	def __init__(self, n):
		self.n = n
		self.rank = [0] * n
		self.parent = [int(j) for j in range(n)]

	def union(self, i, j):
		i = self.find(i)
		j = self.find(j)
		if self.rank[i] == self.rank[j]:
			self.parent[i] = j
			self.rank[j] += 1
		elif self.rank[i] > self.rank[j]:
			self.parent[j] = i
		else:
			self.parent[i] = j

	def find(self, i):
		temp = i
		if self.parent[temp] != temp:
			self.parent[temp] = self.find(self.parent[temp])
		return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC

def main():
	for t in range(int(input())):
		(x1, x2, x3) = [int(j) for j in input().split()]
		(y1, y2, y3) = [int(j) for j in input().split()]
		ans = 0
		a = min(x3, y2)
		x3 -= a
		ans += 2 * a
		ans -= max(0, y3 - x3 - x1) * 2
		print(ans)
main()


t = int(input())
while t:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	n1 = x1 + y1 + z1
	n2 = n1
	count = 0
	if x1 >= z2:
		x1 = x1 - z2
		z2 = 0
		if z1 >= y2:
			count = 2 * y2
			z1 = z1 - y2
			y2 = 0
		else:
			count = 2 * z1
			y2 = y2 - z1
			z1 = 0
		print(count)
	else:
		z2 = z2 - x1
		x1 = 0
		if y1 >= x2:
			y1 = y1 - x2
			x2 = 0
		else:
			x2 = x2 - y1
			y1 = 0
		if z1 >= z2:
			z1 = z1 - z2
			count = 2 * min(z1, y2)
		else:
			z2 = z2 - z1
			count = -2 * min(z2, y1)
		print(count)
	t = t - 1


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = min(z1, y2)
	z1 -= c
	y2 -= c
	c2 = max(0, z2 - (x1 + z1))
	print(2 * c - 2 * c2)


def tc():
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	adiff = min(c, y)
	ans = 2 * adiff
	y -= adiff
	c -= adiff
	if z > a + c:
		ans -= 2 * (z - a - c)
	print(ans)
T = int(input())
for _ in range(T):
	tc()


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(1, itg() + 1):
	a = list(mpint())
	b = list(mpint())
	pair = min(a[2], b[1])
	ans = 2 * pair
	a[2] -= pair
	b[1] -= pair
	b[2] -= a[0] + a[2]
	if b[2] > 0:
		ans -= 2 * b[2]
	print(ans)


for _ in range(int(input())):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	a = min(z1, y2)
	z1 -= a
	y2 -= a
	if z1 > 0:
		x1 += z1
	b = min(x1, z2)
	x1 -= b
	z2 -= b
	a -= z2
	print(2 * a)


for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 0

	def f(a2, b1):
		MIN = min(a2, b1)
		a2 -= MIN
		b1 -= MIN
		return (MIN, a2, b1)
	(MIN, a2, b1) = f(a2, b1)
	ans += MIN * 2
	(MIN, a0, b2) = f(a0, b2)
	(MIN, a2, b2) = f(a2, b2)
	(MIN, a1, b2) = f(a1, b2)
	ans -= MIN * 2
	print(ans)


for _ in range(int(input())):
	(x, y, z) = [int(i) for i in input().split()]
	(a, b, c) = [int(i) for i in input().split()]
	count = x + y + z
	sum1 = 0
	if z > b:
		sum1 = 2 * b
		z -= b
		b = 0
		if c > z:
			c -= z
			z = 0
			if c > x:
				c -= x
				x = 0
				sum1 -= 2 * min(c, y)
			else:
				x -= c
				c = 0
		else:
			z -= c
			c = 0
	else:
		sum1 = 2 * z
		b -= z
		z = 0
		if c > x:
			c -= x
			x = 0
			sum1 -= 2 * min(c, y)
		else:
			x -= c
			c = 0
	print(sum1)


t = int(input())
while t > 0:
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	val = a - z
	if val >= 0:
		print(min(c, y) * 2)
	else:
		temp = abs(val)
		z = z - a
		san = c - z
		if san >= 0:
			c = c - z
			print(min(c, y) * 2)
		else:
			c = c - z
			print(c * 2)
	t = t - 1


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = map(int, input().split())
	ans = min(b1, c) * 2
	b1 -= min(b1, c)
	b -= min(b, a1)
	b -= min(b, b1)
	print(ans - b * 2)


import sys
from sys import stdin, stdout
import math
import time
from functools import lru_cache
from collections import Counter
import heapq
try:
	for _ in range(int(input())):
		(z, o, t) = map(int, input().split())
		(z2, o2, t2) = map(int, input().split())
		ans = min(t, o2)
		f = 0
		if o2 > t:
			f = o2 - t
		if o < f + z2:
			print(2 * ans)
		else:
			print(2 * (ans - (o - (f + z2))))
except EOFError as e:
	print(e)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		ans = 2 * min(z1, y2)
		if y2 > z1:
			y2 -= z1
		else:
			y2 = 0
		y1 -= x2
		y1 -= y2
		if y1 < 0:
			y1 = 0
		ans -= 2 * min(z2, y1)
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def process(a, b, c, d, e, f):
	s = 0
	m2 = min(c, e)
	s += 2 * m2
	c -= m2
	e -= m2
	f -= c
	f -= a
	if f > 0:
		s -= 2 * f
	return s

def main():
	n = int(input())
	results = []
	for i in range(n):
		(f0, f1, f2) = list(map(int, input().split()))
		(s0, s1, s2) = list(map(int, input().split()))
		results.append(process(f0, f1, f2, s0, s1, s2))
	for i in results:
		print(i)
main()


t = int(input())
for _ in range(t):
	score = 0
	(a0, b1, c2) = [int(x) for x in input().split()]
	(x0, y1, z2) = [int(x) for x in input().split()]
	min1 = min(c2, y1)
	score += 2 * min1
	c2 -= min1
	y1 -= min1
	minx = min(b1, x0)
	b1 -= minx
	x0 -= minx
	min2 = min(b1, y1)
	b1 -= min2
	y1 -= min2
	min3 = min(a0, z2)
	a0 -= min3
	z2 -= min3
	min4 = min(b1, z2)
	score -= 2 * min4
	print(score)


for t in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = min(a[2], b[1])
	k2 = max(b[2] - min(a[2] + a[0] - k, b[2]), 0)
	print(2 * k - 2 * k2)


import math
t = int(input())
for w in range(t):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	s = 0
	s += 2 * min(a[2], b[1])
	a[2] -= min(a[2], b[1])
	b[1] -= min(a[2], b[1])
	b[2] -= min(a[0] + a[2], b[2])
	print(s - 2 * b[2])


for _ in range(int(input())):
	ans = 0
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	twomax = min(a[2], b[1])
	ans += 2 * twomax
	a[2] -= twomax
	b[1] -= twomax
	twominimise = min(a[0], b[2])
	a[0] -= twominimise
	b[2] -= twominimise
	twokill = min(a[2], b[2])
	a[2] -= twokill
	b[2] -= twokill
	ans -= min(b[2], a[1]) * 2
	print(ans)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = b[2] - a[0] - max(0, a[2] - b[1])
	if c > 0:
		print(2 * min(b[1], a[2]) - 2 * c)
	else:
		print(2 * min(b[1], a[2]))


T = int(input())
while T > 0:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	res = 0
	if z1 > y2:
		res += y2 * 2
		left = max(0, z2 - (z1 - y2) - x1)
		res -= left * 2
	else:
		res += z1 * 2
		left = max(0, z2 - x1)
		res -= left * 2
	print(res)
	T -= 1


n = int(input())
a = []
b = []
for i in range(n):
	a.append([int(j) for j in input().split()])
	b.append([int(j) for j in input().split()])
for i in range(n):
	if b[i][2] >= a[i][0] + a[i][2]:
		print(-(b[i][2] - a[i][0] - a[i][2]) * 2)
	elif b[i][2] > a[i][0]:
		k = a[i][0] + a[i][2] - b[i][2]
		print((max(b[i][1], k) - abs(b[i][1] - k)) * 2)
	else:
		print((max(b[i][1], a[i][2]) - abs(b[i][1] - a[i][2])) * 2)


import sys
import os

def get_inp():
	return sys.stdin.readline().strip()

def get_inps():
	return sys.stdin.readline().strip().split()

def println(str):
	return sys.stdout.write(str + '\n')

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(get_inp())
while (t := (t - 1)) >= 0:
	(x1, y1, z1) = map(int, get_inps())
	(x2, y2, z2) = map(int, get_inps())
	sum = min(z1, y2) * 2
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	m = min(z2, x1)
	z2 -= m
	x1 -= m
	m = min(z2, z1)
	z2 -= m
	z1 -= m
	m = min(y2, y1)
	y2 -= m
	y1 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	y1 = max(0, y1)
	if z2 > 0:
		sum = sum - min(z2, y1) * 2
	print(sum)


def parr(arr):
	print(*arr, sep=' ')
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	ans += min(z1, y2) * 2
	rem_two_a = z1 - min(z1, y2)
	rem_two_b = max(z2 - rem_two_a - x1, 0)
	ans -= min(rem_two_b, y1) * 2
	print(ans)


def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	m = min(z1, y2)
	ans = 2 * m
	z1 -= m
	y2 -= m
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(y1, x2)
	y1 -= m
	x2 -= m
	m = min(z1, z2)
	z1 -= m
	z2 -= m
	m = min(y1, y2)
	y1 -= m
	y2 -= m
	ans -= 2 * min(y1, z2)
	print(ans)
for test in range(int(input())):
	solve()


t = int(input())
while t > 0:
	(a0, a1, a2) = [int(x) for x in input().split()]
	(b0, b1, b2) = [int(x) for x in input().split()]
	ans = 0
	if b1 >= a2:
		ans += a2 * 2
		b1 -= a2
		a2 = 0
	else:
		ans += 2 * b1
		a2 -= b1
		b1 = 0
	if a1 > b0 + b1:
		ans -= 2 * (a1 - b0 - b1)
	print(ans)
	t -= 1


T = int(input())
for _ in range(T):
	(x1, y1, z1) = tuple(map(int, input().split()))
	(x2, y2, z2) = tuple(map(int, input().split()))
	p1 = min(z1, y2) * 2
	(z1, y2) = (z1 - min(z1, y2), y2 - min(z1, y2))
	p2 = min(z1, z2) * 0
	(z1, z2) = (z1 - min(z1, z2), z2 - min(z1, z2))
	p3 = min(z1, x2) * 0
	(z1, x2) = (z1 - min(z1, x2), x2 - min(z1, x2))
	q1 = min(y1, x2) * 0
	(y1, x2) = (y1 - min(y1, x2), x2 - min(y1, x2))
	q2 = min(y1, y2) * 0
	(y1, y2) = (y1 - min(y1, y2), y2 - min(y1, y2))
	q3 = min(y1, z2) * -2
	(y1, z2) = (y1 - min(y1, z2), z2 - min(y1, z2))
	print(p1 + p2 + p3 + q1 + q2 + q3)


for t in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	count = min(z1, y2)
	z1 -= count
	y2 -= count
	count *= 2
	tmp = min(z1, z2)
	z1 -= tmp
	z2 -= tmp
	tmp = min(z1, x2)
	z1 -= tmp
	x2 -= tmp
	tmp = min(z2, x1)
	z2 -= tmp
	x1 -= tmp
	tmp = min(z2, y1)
	count -= 2 * tmp
	print(count)


for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	m = min(z1, y2)
	z1 -= m
	s = 2 * m
	m = min(x1 + z1, z2)
	z2 -= m
	if z2 > 0:
		s -= z2 * 2
	print(s)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	g = min(c, e)
	r = g * 2
	c = c - g
	e = e - g
	if a + c >= f:
		print(r)
	else:
		f = f - (a + c)
		r = r - 2 * f
		print(r)


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	(a0, a1, a2) = map(int, sys.stdin.readline().split())
	(b0, b1, b2) = map(int, sys.stdin.readline().split())
	ans = 0
	ans += 2 * min(a2, b1)
	a2 -= min(a2, b1)
	b1 -= min(a2, b1)
	if b2 > a2 + a0:
		b2 -= a0 + a2
		a0 = 0
		a2 = 0
		ans += -2 * min(b2, a1)
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c) = [int(i) for i in input().split()]
	(d, e, f) = [int(i) for i in input().split()]
	t = 0
	if c >= e:
		t = e * 2
		c -= e
		e = 0
	else:
		t = c * 2
		e -= c
		c = 0
	if c > 0:
		if c >= f:
			c -= f
			f = 0
		else:
			f -= c
			c = 0
	if a > 0:
		if a >= f:
			a -= f
			f = 0
		else:
			f -= a
			a = 0
	if b > 0:
		if e >= b:
			e -= b
			b = 0
		else:
			b -= e
			e = 0
		if d >= b:
			d -= b
			b = 0
		else:
			b -= d
			d = 0
	t -= min(b, f) * 2
	print(t)


from sys import stdin, stdout
try:
	t = int(input())
	for i in range(t):
		(on, tw, th) = map(int, input().split())
		(on1, tw1, th1) = map(int, input().split())
		m1 = min(th, tw1)
		ans = 0
		ans += m1 * 2
		th = th - m1
		tw1 = tw1 - m1
		ot = on + th
		if th1 > ot:
			ans -= 2 * (th1 - ot)
		print(ans)
except:
	pass


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	a = []
	b = []
	xx = min(z1, y2)
	ans += 2 * xx
	z1 = z1 - xx
	y2 = y2 - xx
	xx = min(z1, z2)
	z1 = z1 - xx
	z2 = z2 - xx
	xx = min(x1, z2)
	x1 = x1 - xx
	z2 = z2 - xx
	ans -= 2 * min(z2, y1)
	print(ans)


for i in range(int(input())):
	(x3, x2, x1) = map(int, input().split())
	(y3, y2, y1) = map(int, input().split())
	if y2 >= x1 + x2:
		print(x1 * 2)
	elif y2 <= x1:
		x1 = x1 - y2
		if y1 > x1 + x3:
			print(y2 * 2 - (y1 - x1 - x3) * 2)
		else:
			print(y2 * 2)
	elif y1 > x3:
		print(x1 * 2 - (y1 - x3) * 2)
	else:
		print(x1 * 2)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	q = min(c, y)
	out = q * 2
	c -= q
	y -= q
	q = min(c, z)
	c -= q
	z -= q
	q = min(c, x)
	c -= q
	x -= q
	q = min(b, y)
	b -= q
	y -= q
	q = min(b, x)
	b -= q
	x -= q
	q = min(b, z)
	out -= q * 2
	print(out)


import sys
from collections import deque

def main():
	tn = int(input())
	for ti in range(tn):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		s = 0
		if z1:
			a = min(z1, y2)
			s += 2 * a
			z1 -= a
			y2 -= a
		if z1:
			a = min(z1, z2)
			z1 -= a
			z2 -= a
		if z1:
			a = min(z1, x2)
			z1 -= a
			x2 -= a
		s -= max(0, y1 - y2 - x2) * 2
		print(s)
main()


T = int(input())
for i in range(T):
	(z, o, t) = map(int, input().split())
	(z1, o1, t1) = map(int, input().split())
	Sum = 0
	t1 -= min(t1, z)
	if t1 > 0:
		k = min(t1, t)
		t1 -= k
		t -= k
	else:
		k = min(t1, o1)
		Sum = 2 * k
		t -= k
	if t1 > 0:
		Sum = -(t1 * 2)
	else:
		k = min(t, o1)
		Sum = 2 * k
	print(Sum)


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 0
	mini = min(c, y)
	ans += 2 * mini
	c = c - mini
	y = y - mini
	z = z - (a + c)
	b = b - x
	if z > 0 and b > 0:
		ans -= 2 * min(z, b)
	print(ans)


t = int(input())
for _ in range(t):
	(z, y, x) = map(int, input().split())
	(z1, y1, x1) = map(int, input().split())
	ans = min(x, y1) * 2
	mini = min(x, y1)
	x -= mini
	y1 -= mini
	if z + x <= x1:
		ans -= 2 * (x1 - (z + x))
	print(ans)


t = int(input())
for i in range(t):
	sum = 0
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	sum = 2 * min(a2, b1)
	if a1 - b0 > 0 and a0 - b2 < 0:
		a1 = abs(a1 - b0)
		b2 = abs(a0 - b2)
		sum = sum + -2 * min(a1, b2)
	print(sum)


def seq(a, b):
	ans = 0
	if a[2] > b[1]:
		a[2] = a[2] - b[1]
		ans += 2 * b[1]
		b[1] = 0
	if a[2] <= b[1]:
		ans += 2 * a[2]
		a[2] = 0
		b[1] = b[1] - a[2]
	if a[0] < b[2] and b[2] - a[0] > a[2]:
		ans += (b[2] - a[0] - a[2]) * -2
		a[0] = 0
		a[2] = 0
	return ans
t = int(input())
for u in range(t):
	A = list(map(int, input().strip().split()))
	B = list(map(int, input().strip().split()))
	print(seq(A, B))


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum1 = 0
	poison = 0
	if z1 >= y2:
		sum1 += 2 * y2
		z1 -= y2
		y2 = 0
		if z1 + x1 >= z2:
			print(sum1)
		else:
			z2 -= z1 + x1
			poison = 2 * z2
			sum1 -= poison
			print(sum1)
	else:
		sum1 += 2 * z1
		y2 -= z1
		z1 = 0
		if x1 >= z2:
			print(sum1)
		else:
			z2 -= x1
			poison = 2 * z2
			sum1 -= poison
			print(sum1)


for _ in range(int(input())):
	(x, y, z) = [int(x) for x in input().split()]
	(a, b, c) = [int(x) for x in input().split()]
	total = 2 * min(z, b)
	d = z
	z -= min(z, b)
	b -= min(d, b)
	e = y
	y -= min(y, a)
	a -= min(e, a)
	f = y
	y -= min(y, b)
	b -= min(f, b)
	c -= min(x, c)
	c -= min(z, c)
	total -= 2 * min(y, c)
	print(total)


t = int(input())
for q in range(t):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	m = min(x0, y2)
	y2 -= m
	x0 -= m
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	s = 2 * m
	s = s - 2 * min(x1, y2)
	print(s)


def solve():
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(y1, x2)
	x2 -= m
	y1 -= m
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	sum = 2 * m
	sum -= 2 * min(y1, z2)
	print(sum)
	return
T = int(input())
for _ in range(T):
	solve()


t = int(input())
while t > 0:
	t -= 1
	(x, y, z) = map(int, input().split())
	(m, n, o) = map(int, input().split())
	if x >= o:
		ans = 2 * min(z, n)
	elif o <= x + z:
		ans = min(x + z - o, n) * 2
	elif o > x + z:
		ans = -(o - x - z) * 2
	print(ans)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
from sys import stdin, stdout
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	answer = min(z1, y2) * 2
	temp = min(z1, y2)
	y2 -= temp
	z1 -= temp
	temp = min(z2, x1)
	z2 -= temp
	x1 -= temp
	temp = min(z2, z1)
	z2 -= temp
	z1 -= temp
	temp = min(y1, y2)
	y1 -= temp
	y2 -= temp
	temp = min(y1, x2)
	y1 -= temp
	x2 -= temp
	answer -= min(z2, y1) * 2
	print(answer)
sys.exit(0)

class Person:

	def __init__(self, name, age):
		self.name = name
		self.age = age
p1 = Person('heelo', 27)
print(help(Person))
age = 26
name = 'Swaroop'
print('Возрас {} -- {} лет'.format(name, age))
print(help(object))


t = int(input())
while t > 0:
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	c_sum = 0
	a = x1
	b = y2
	if z1 >= y2:
		c_sum = y2 * 2
		z1 -= y2
		y2 = 0
		if z2 > z1:
			z2 -= z1
			if z2 > x1:
				z2 -= x1
				c_sum -= z2 * 2
	else:
		c_sum = z1 * 2
		y2 -= z1
		z1 = 0
		if y1 > y2:
			y1 -= y2
			if y1 > x2:
				y1 -= x2
				c_sum -= y1 * 2
	print(c_sum)
	t -= 1


t = int(input())
for _ in range(t):
	(a0, a1, a2) = (int(i) for i in input().split())
	(b0, b1, b2) = (int(i) for i in input().split())
	print(min(a2, b1) * 2 - max(0, b2 - max(0, a2 - b1) - a0) * 2)


n = int(input())
input_list = []
for i in range(n):
	a = input()
	b = input()
	lis = [a, b]
	input_list.append(lis)
for item in input_list:
	a = list(map(lambda x: int(x), item[0].split()))
	b = list(map(lambda x: int(x), item[1].split()))
	x1 = a[0]
	y1 = a[1]
	z1 = a[2]
	x2 = b[0]
	y2 = b[1]
	z2 = b[2]
	sum = 0
	if z1 <= y2:
		sum += 2 * z1
		if y1 <= y2 - z1:
			sum += 0
		else:
			sum += 0
			if y1 - y2 + z1 <= x2:
				sum += 0
			else:
				sum += 0
				if y1 - y2 + z1 - x2 <= z2:
					sum += -2 * (y1 - y2 + z1 - x2)
				else:
					sum += -2 * z2
	else:
		sum += 2 * y2
		if z1 - y2 <= z2:
			sum += 0
			if y1 <= x2:
				sum += 0
			else:
				sum += 0
				if y1 - x2 <= z2:
					sum += -2 * (y1 - x2)
				else:
					sum += -2 * z2
		else:
			sum += 0
			if z1 - y2 - z2 <= x2:
				sum += 0
	print(sum)


t = int(input())
myList = []
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	(d, e, f) = list(map(int, input().split()))
	mySum = min(c, e) * 2
	mySum -= min(b, max(f - a - max(c - e, 0), 0)) * 2
	myList.append(mySum)
for elem in myList:
	print(elem)


for i in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	k = min(c, y)
	ans = 2 * k
	c -= k
	y -= k
	if a + c < z:
		ans -= 2 * (z - a - c)
	print(ans)


def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	free = z1 - min(z1, y2)
	free2 = max(z2 - free - x1, 0)
	print(2 * min(z1, y2) - 2 * free2)
for _ in range(int(input())):
	solve()


def answer(x1, y1, z1, x2, y2, z2):
	sum = min(z1, y2) * 2
	extra_ones = max(y2 - z1, 0)
	sum -= min(max(y1 - (x2 + extra_ones), 0), z2) * 2
	return sum

def main():
	t = int(input())
	x1 = [0] * t
	y1 = [0] * t
	z1 = [0] * t
	x2 = [0] * t
	y2 = [0] * t
	z2 = [0] * t
	for j in range(t):
		(x1[j], y1[j], z1[j]) = [int(i) for i in input().split()]
		(x2[j], y2[j], z2[j]) = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(x1[j], y1[j], z1[j], x2[j], y2[j], z2[j]))
main()


from math import *
from sys import *
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 0
	m = min(c, y)
	ans = ans + m * 2
	k = max(0, c - y)
	if z <= a + k:
		pass
	else:
		p = z - (a + k)
		p = p * 2
		ans = ans - p
	print(ans)


t = int(input())
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	s = 0
	m = min(a0, b2)
	a0 -= m
	b2 -= m
	m = min(b0, a1)
	b0 -= m
	a1 -= m
	m = min(a2, b1)
	a2 -= m
	b1 -= m
	s += 2 * m
	s -= 2 * min(a1, b2)
	print(s)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
for _ in range(int(input())):
	(a0, a1, a2) = value()
	(b0, b1, b2) = value()
	ans = 0
	mn = min(a2, b1)
	ans += mn * 2
	a2 -= mn
	b1 -= mn
	if a2 > 0:
		mn = min(a2, b2)
		a2 -= mn
		b2 -= mn
	if b2 > 0:
		mn = min(b2, a0)
		b2 -= mn
		a0 -= mn
	if b2 > 0:
		mn = min(b2, a1)
		ans -= mn * 2
	print(ans)


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


t = int(input())
while t > 0:
	(a0, a1, a2) = map(int, input().strip().split())
	(b0, b1, b2) = map(int, input().strip().split())
	answer = 0
	pair_a2b1 = min(a2, b1)
	a2 -= pair_a2b1
	b1 -= pair_a2b1
	answer += pair_a2b1 * 2
	pair_a0b2 = min(a0, b2)
	b2 -= pair_a0b2
	a0 -= pair_a0b2
	pair_a2b2 = min(a2, b2)
	a2 -= pair_a2b2
	b2 -= pair_a2b2
	pair_a0b1 = min(a0, b1)
	b1 -= pair_a0b1
	a0 -= pair_a0b1
	pair_a1b2 = min(a1, b2)
	answer -= pair_a1b2 * 2
	print(answer)
	t -= 1


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	p = min(z1, y2)
	ans += 2 * p
	if y1 <= x2 + (y2 - p):
		ans += 0
	else:
		q = y1 - (x2 + (y2 - p))
		ans -= 2 * q
	print(ans)


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 _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maxi = min(a[2], b[1]) * 2
	a[1] = a[1] - min(a[1], b[0])
	if a[0] <= b[2]:
		maxi = maxi - min(b[2] - a[0], a[1]) * 2
	print(maxi)


for _ in range(int(input())):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	x = min(x2, y1)
	x2 -= x
	y1 -= x
	ans = x * 2
	y2 -= min(y2, x0 + x2)
	print(ans - y2 * 2)


t = int(input())
for i in range(t):
	s1 = input().split()
	s2 = input().split()
	x1 = int(s1[0])
	y1 = int(s1[1])
	z1 = int(s1[2])
	x2 = int(s2[0])
	y2 = int(s2[1])
	z2 = int(s2[2])
	count = 0
	l = min(z1, y2)
	count += 2 * l
	z1 = z1 - l
	y2 = y2 - l
	t = min(z2, z1 + x1)
	z2 = z2 - t
	q = min(y1, x2 + y2)
	y1 = y1 - q
	count -= 2 * min(z2, y1)
	print(count)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline

def f(a, b):
	temp = min(a.b)
	a -= temp
	b -= temp
	return temp
for ii in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	temp = min(z1, y2)
	ans = temp * 2
	z1 -= temp
	y2 -= temp
	temp = min(y1, x2)
	y1 -= temp
	x2 -= temp
	temp = min(x1, z2)
	x1 -= temp
	z2 -= temp
	temp = min(x1, x2)
	x1 -= temp
	x2 -= temp
	temp = min(x1, y2)
	x1 -= temp
	y2 -= temp
	temp = min(y1, y2)
	y1 -= temp
	y2 -= temp
	temp = min(z1, y2)
	z1 -= temp
	y2 -= temp
	temp = min(z1, z2)
	z1 -= temp
	z2 -= temp
	temp = min(y1, z2)
	y1 -= temp
	z2 -= temp
	ans -= temp * 2
	print(ans)


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


t = int(input())
for _ in range(t):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ans = 0
	ans += min(l1[2], l2[1]) * 2
	l1[2] -= ans // 2
	if l2[2] <= l1[0]:
		print(ans)
	else:
		l2[2] -= l1[0]
		if l1[2] > 0:
			l2[2] -= min(l1[2], l2[2])
		if l2[2] > 0:
			ans -= min(l1[1], l2[2]) * 2
		print(ans)


T = int(input())

def delNum(f, s):
	tmp = min(a[f], b[s])
	a[f] -= tmp
	b[s] -= tmp
for _ in range(T):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tmp = min(a[2], b[1])
	first = 2 * tmp
	a[2] -= tmp
	b[1] -= tmp
	delNum(2, 2)
	delNum(0, 2)
	delNum(1, 0)
	delNum(1, 1)
	tmp = min(a[1], b[2])
	second = 2 * tmp
	print(first - second)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 2 * min(z1, y2)
	if z1 > y2:
		c = z1 - y2 + x1
		if c >= z2:
			print(ans)
		else:
			kk = z2 - c
			w = y1 - x2
			ans -= 2 * w
			print(ans)
	else:
		c = y2 - z1 + x2
		if c >= y1:
			print(ans)
		else:
			kk = y1 - c
			ans -= 2 * kk
			print(ans)


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def primeFactors(n):
	j = []
	while n % 2 == 0:
		j.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			j.append(int(n))
			n = n / i
	if n > 2:
		j.append(int(n))
	return j

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def main():
	for _ in range(ii()):
		(x1, y1, z1) = mi()
		(x2, y2, z2) = mi()
		res = 0
		res1 = 0
		res1 += min(z1, y2) * 2
		res += min(z1, y2) * 2
		z1 -= min(z1, y2)
		if z2 > x1 + z1:
			if y1 > 0:
				res -= (z2 - (x1 + z1)) * 2
		print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(ze1, on1, tw1) = map(int, input().split())
	(ze2, on2, tw2) = map(int, input().split())
	if ze1 >= tw2:
		print(2 * min(tw1, on2))
	else:
		tw2 = tw2 - ze1
		if tw1 >= tw2:
			tw1 = tw1 - tw2
			print(2 * min(on2, tw1))
		else:
			tw1 = tw1 - tw2
			print(2 * min(on2, tw1))


t = int(input())
for i in range(t):
	(x1, y1, z1) = [int(m) for m in input().split()[:3]]
	(x2, y2, z2) = [int(m) for m in input().split()[:3]]
	c = 0
	if z1 > 0:
		if y2 > 0 and z1 > 0:
			l1 = min(y2, z1)
			f1 = 2 * l1
			c += f1
			z1 -= l1
			y2 -= l1
		if z2 > 0 and z1 > 0:
			l2 = min(z2, z1)
			f2 = 0 * l2
			c += f2
			z1 -= l2
			z2 -= l2
		if x2 > 0 and z1 > 0:
			l3 = min(x2, z1)
			f3 = 0 * l3
			c += f3
			z1 -= l3
			x2 -= l3
	if y1 > 0:
		if x2 > 0 and y1 > 0:
			l5 = min(x2, y1)
			f5 = 0 * l5
			y1 -= l5
			x2 -= l5
		if y2 > 0 and y1 > 0:
			l4 = min(y2, y1)
			f4 = 0 * l4
			y1 -= l4
			y2 -= l4
		if z2 > 0 and y1 > 0:
			l6 = min(z2, y1)
			f6 = -2 * l6
			c += f6
			y1 -= l6
			z2 -= l6
	else:
		pass
	print(c)


for _ in range(int(input())):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	ans = 0
	if x2 > y1:
		ans = y1 * 2
		temp = (x1 - y0) * (x1 - y0 > 0)
		ans -= temp * 2
		print(ans)
	else:
		ans = x2 * 2
		temp = y1 - x2 + y0
		temp = x1 - temp
		temp = temp * (temp > 0)
		ans -= temp * 2
		print(ans)


R = lambda : map(int, input().split())
(T,) = R()
exec('a,b,c=R();d,e,f=R();print(min(c,e,d+e-b)*2);' * T)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def fn1(x1, y1, z1, x2, y2, z2):
	ans = 0
	if z1 >= y2:
		ans += 2 * y2
		z1 -= y2
		y2 = 0
		if z1 >= z2:
			z1 -= z2
			z2 = 0
			return ans
		else:
			z2 -= z1
			z1 = 0
			if z2 >= x1:
				z2 -= x1
				x1 = 0
				ans -= z2
				return ans
			else:
				x1 -= z2
				z2 = 0
				return ans
	else:
		ans += 2 * z1
		y2 -= z1
		z1 = 0
		if y1 >= y2:
			y1 -= y2
			y2 = 0
			if z2 >= x1:
				z2 -= x1
				x1 = 0
				ans -= z2
				return ans
			else:
				x1 -= z2
				z2 = 0
				return ans
		else:
			y2 -= y1
			y1 = 0
			return ans

def fn2(x1, y1, z1, x2, y2, z2):
	ans = 0
	if z2 >= x1:
		z2 -= x1
		x1 = 0
		if z2 >= z1:
			z2 -= z1
			z1 = 0
			ans = -2 * z2
			return ans
		elif z1 >= y2:
			ans += 2 * y2
			z1 -= y2
			y2 = 0
			return ans
		else:
			ans += 2 * z1
			y2 -= z1
			z1 = 0
			return ans
	else:
		x1 -= z2
		z2 = 0
		if z1 >= y2:
			ans += 2 * y2
			z1 -= y2
			y2 = 0
			return ans
		else:
			ans += 2 * z1
			y2 -= z1
			z1 = 0
			return ans
T = inp()
for t in range(T):
	(x1, y1, z1) = invr()
	(x2, y2, z2) = invr()
	ans = 0
	if z1 >= y2:
		ans += 2 * y2
		z1 -= y2
		y2 = 0
		print(ans + fn2(x1, y1, z1, x2, y2, z2))
	else:
		ans += 2 * z1
		y2 -= z1
		z1 = 0
		print(ans + fn2(x1, y1, z1, x2, y2, z2))


I = lambda : list(map(int, input().split()))
for i in range(int(input())):
	(l1, l2, w) = (I(), I(), 0)
	for i in range(2, 0, -1):
		q = min(l1[i], l2[i - 1])
		w += q * (i - 1) * i
		l1[i] -= q
		l2[i - 1] -= q
	for i in range(3):
		q = min(l1[i], l2[i])
		l1[i] -= q
		l2[i] -= q
	for i in range(3):
		for j in range(i + 1, 3):
			q = min(l1[i], l2[j])
			w -= q * i * j
			l1[i] -= q
			l2[j] -= q
	print(w)


c = int(input())
for x in range(c):
	l1 = [int(x) for x in input().split(' ')]
	l2 = [int(x) for x in input().split(' ')]
	l = min(l1[2], l2[1])
	l2[1] -= l
	l1[2] -= l
	if l1[1] - l2[1] - l2[0] < l2[2] - l1[0] - l1[2]:
		minus = max(0, l1[1] - l2[1] - l2[0])
	else:
		minus = max(0, l2[2] - l1[0] - l1[2])
	print(2 * (l - minus))


def solve():
	(x1, y1, z1) = [int(v) for v in input().split()]
	(x2, y2, z2) = [int(v) for v in input().split()]
	total = 2 * min(z1, y2)
	z1 -= total // 2
	y2 -= total // 2
	y1 -= x2
	y1 -= y2
	z2 -= z1
	z2 -= x1
	y1 = max(0, y1)
	z2 = max(0, z2)
	total -= 2 * min(y1, z2)
	print(total)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	s = 0
	nb = min(z1, y2)
	z1 -= nb
	y2 -= nb
	s += 2 * nb
	nb = min(x1, z2)
	x1 -= nb
	z2 -= nb
	nb = min(z1, z2)
	z1 -= nb
	z2 -= nb
	nb = min(x1, z2)
	x1 -= nb
	z2 -= nb
	s -= 2 * z2
	print(s)


t = int(input())
for i in range(t):
	(x1, y1, z1) = (int(i) for i in input().split())
	(x2, y2, z2) = (int(i) for i in input().split())
	s = 2 * min(z1, y2) - 2 * max(0, min(z2 - x1, z2 - x1 - z1 + y2))
	print(s)


def ter_seq(x1, y1, z1, x2, y2, z2):
	sum = 0
	m = min(z1, y2)
	sum += 2 * m
	z1 -= m
	y2 -= m
	if z2 <= x1:
		return sum
	else:
		z2 -= x1
		if z2 <= z1:
			return sum
		else:
			z2 -= z1
			sum -= 2 * z2
			return sum
t = int(input())
for _ in range(t):
	xyz1 = input().split()
	xyz2 = input().split()
	x1 = int(xyz1[0])
	y1 = int(xyz1[1])
	z1 = int(xyz1[2])
	x2 = int(xyz2[0])
	y2 = int(xyz2[1])
	z2 = int(xyz2[2])
	print(ter_seq(x1, y1, z1, x2, y2, z2))


test_cases = int(input())
for test_case in range(test_cases):
	(a0, a1, a2) = list(map(int, input().split()))
	(b0, b1, b2) = list(map(int, input().split()))
	ans = 0
	if a2 != 0 and b1 != 0:
		if a2 >= b1:
			ans += b1 * 2
			b1 = 0
			a2 = b1 - a2
		else:
			ans += a2 * 2
			b1 = b1 - a2
			a2 = 0
	if b0 + b1 < a1:
		a1 = a1 - (b0 + b1)
		ans -= a1 * 2
	print(ans)


t = int(input())
for i in range(0, t):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	if l1[2] > l2[1]:
		if l1[1] > l2[0]:
			print(-2 * (l1[1] - l2[0]) + 2 * l2[1])
		else:
			print(2 * l2[1])
	elif l2[2] > l1[0]:
		print(-2 * (l2[2] - l1[0]) + 2 * l1[2])
	else:
		print(2 * l1[2])


from sys import stdin, stdout
ans = []

def main():
	count = 0
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	if a[2] > b[1]:
		count += 2 * b[1]
		a[2] -= b[1]
		b[1] = 0
	else:
		count += 2 * a[2]
		b[1] -= a[2]
		a[2] = 0
	if b[2]:
		temp = min(b[2], a[0])
		b[2] -= temp
		a[0] -= temp
		if b[2] and a[2]:
			temp = min(b[2], a[2])
			b[2] -= temp
			a[2] -= temp
	count -= 2 * b[2]
	ans.append(str(count))
for _ in range(int(stdin.readline())):
	main()
stdout.write('\n'.join(ans))


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	mi = min(z1, y2)
	ans = 2 * mi
	z1 -= mi
	y2 -= mi
	y1 -= y2 + x2
	z2 -= x1 + z1
	if y1 > 0 and z2 > 0:
		ans -= 2 * min(y1, z2)
	print(ans)


for _ in range(int(input())):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	t1 = min(c1, b2)
	ans = t1 * 2
	c1 -= t1
	a2 -= t1
	if b1 > a2 + b2:
		ans -= min(b1 - a2 - b2, c2) * 2
	print(ans)


T = int(input())
for t in range(T):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 0
	goods = min(a2, b1)
	ans += goods * 2
	n = a0 + a1 + a2 - goods
	if a1 + b2 > n:
		ans -= (b2 + a1 - n) * 2
	print(ans)


import io, os
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(xa, ya, za) = map(int, input().split())
	(xb, yb, zb) = map(int, input().split())
	ans = 0
	pq = min(za, yb)
	ans += pq * 2
	za -= pq
	yb -= pq
	pq1 = min(zb, za)
	zb -= pq1
	pq2 = min(zb, xa)
	zb -= pq2
	pq3 = min(ya, yb)
	ya -= pq3
	pq4 = min(ya, xb)
	ya -= pq4
	ans -= min(ya, zb) * 2
	print(ans)


import sys, math
import io, os

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	(x1, y1, z1) = mdata()
	(x2, y2, z2) = mdata()
	ans = 0
	(z2, x1) = (max(0, z2 - x1), max(0, x1 - z2))
	(z2, z1) = (max(0, z2 - z1), max(0, z1 - z2))
	ans -= 2 * min(z2, y1)
	(z2, y1) = (max(0, z2 - y1), max(0, y1 - z2))
	ans += 2 * min(z1, y2)
	(y2, z1) = (max(0, y2 - z1), max(0, z1 - y2))
	out(ans)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(a, b, c) = mapi()
	(x, y, z) = mapi()
	res = 0
	res += 2 * min(c, y)
	(c, y) = (c - min(c, y), y - min(c, y))
	z -= min(z, a)
	z -= min(c, z)
	print(res - 2 * z)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	z1 = z - min(z, a)
	a -= min(z, a)
	z = z1
	z1 = z - min(z, c)
	c -= min(z, c)
	z = z1
	if z == 0 and c == 0:
		print(0)
	elif c != 0:
		print(min(c, y) * 2)
	elif z != 0:
		print(-min(z, b) * 2)


t = int(input())
for f in range(t):
	(x, y, z) = map(int, input().rstrip().split())
	(a, b, c) = map(int, input().rstrip().split())
	ans = 0
	while z > 0:
		if b > 0:
			i = min(z, b)
			b -= i
			z -= i
			ans += 2 * i
		elif c > 0:
			j = min(z, c)
			c -= j
			z -= j
		elif a > 0:
			k = min(z, a)
			a -= k
			z -= k
	while y > 0:
		if b > 0:
			i = min(y, b)
			b -= i
			y -= i
		elif a > 0:
			j = min(y, a)
			a -= j
			y -= j
		elif c > 0:
			k = min(y, c)
			c -= k
			y -= k
			ans -= 2 * k
	print(ans)


import sys
inputlines = sys.stdin.readlines()
number_of_testcases = int(inputlines[0])
for i in range(number_of_testcases):
	(x1, y1, z1) = list(map(int, inputlines[2 * i + 1].split(' ')))
	(x2, y2, z2) = list(map(int, inputlines[2 * i + 2].split(' ')))
	minimum = min(z1, y2)
	sum = 2 * minimum
	z1 -= minimum
	y2 -= minimum
	z2 -= z1
	z2 -= x1
	if z2 > 0:
		sum = sum - z2 * 2
	print(sum)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = -1000000000.0
	s = -1000000000.0
	s1 = -1000000000.0
	if y2 <= z1:
		s = y2 * 2
		if x1 + z1 - y2 < z2:
			s -= min(y1, z2 - x1 - z1 + y2) * 2
	else:
		s1 = z1 * 2
		if x1 < z2:
			s1 -= min(y1, z2 - x1) * 2
	print(max(s, s1))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()
from random import randint
from collections import defaultdict, deque

class Graph(object):

	def __init__(self, dic):
		self.dict = dic
		self.vertex = set()

	def addedge(self, a, b):
		if self.dict[a] == []:
			self.vertex.add(a)
		if b != None:
			self.dict[a].append(b)

	def con_com_util(self, i, unvisited, count, comp):
		for j in self.dict[i]:
			if j in unvisited:
				unvisited.remove(j)
				comp[count].append(j)
				comp = self.con_com_util(j, unvisited, count, comp)
		return comp

	def conn_components(self):
		unvisited = self.vertex.copy()
		count = 0
		comp = defaultdict(list)
		while unvisited:
			i = unvisited.pop()
			comp[count].append(i)
			comp = self.con_com_util(i, unvisited, count, comp)
			count += 1
		return (count, comp)

def countSetBits(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count
from bisect import bisect_left as bl

def solve():
	(x1, y1, z1) = sep()
	(x2, y2, z2) = sep()
	ans = 0
	k1 = min(z1, y2)
	ans += 2 * k1
	z1 -= k1
	y2 -= k1
	ans += 0
	k2 = min(z2, x1)
	z2 -= k2
	x1 -= k2
	k3 = min(z1, z2)
	z1 -= k3
	z2 -= k3
	k5 = min(y1, y2)
	y1 -= k5
	y2 -= k5
	k4 = min(z2, y1)
	ans -= 2 * k4
	print(ans)
testcase(int(inp()))


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


def ans():
	N = int(input())
	for i in range(N):
		A = input().strip().split()
		B = input().strip().split()
		a = int(A[0])
		b = int(A[1])
		c = int(A[2])
		d = int(B[0])
		e = int(B[1])
		f = int(B[2])
		g = 0
		if c >= e:
			g += e * 2
			c = c - e
			e = 0
			if a + c > f:
				g = g
			else:
				g -= (f - a - c) * 2
		elif e > c:
			g += c * 2
			e = e - c
			c = 0
			if a + c > f:
				g = g
			else:
				g -= (f - a - c) * 2
		print(g)
ans()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	ans = ''
	for _ in range(int(ii())):
		(x, y, z) = mi()
		(x1, y1, z1) = mi()
		total = min(y1, z)
		y1 -= total
		z -= total
		tmp2 = x
		if z > 0:
			tmp2 += z
		neg = 0
		if z1 > tmp2:
			neg = z1 - tmp2
		x = total * 2 - neg * 2
		ans += str(x) + '\n'
	print(ans)
main()


def main():
	for tt in range(int(input())):
		(x0, x1, x2) = map(int, input().split())
		(y0, y1, y2) = map(int, input().split())
		k = min(x2, y1)
		g = 0
		if y2 > x0:
			g = y2 - x0
			if k == x2:
				g = g
			elif k < x2:
				r = x2 - k
				if r >= g:
					g = 0
				else:
					g = g - r
		print(k * 2 - g * 2)
main()


cases = int(input())
for i in range(cases):
	line1 = input().split(' ')
	x1 = int(line1[0])
	y1 = int(line1[1])
	z1 = int(line1[2])
	line2 = input().split(' ')
	x2 = int(line2[0])
	y2 = int(line2[1])
	z2 = int(line2[2])
	s = 0
	two1 = min(z1, y2)
	two = two1 * 2
	s += two
	y2 -= two1
	c1 = y2 + x2
	if y1 > c1:
		s -= (y1 - c1) * 2
	print(s)


t = int(input())
while t:
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	summ = 0
	mn = min(x0, y2)
	x0 -= mn
	y2 -= mn
	mn = min(x1, y0)
	x1 -= mn
	y0 -= mn
	mn = min(x2, y1)
	x2 -= mn
	y1 -= mn
	summ += 2 * mn
	summ -= 2 * min(x1, y2)
	print(summ)
	t -= 1


_ = int(input())
while _:
	(a, b, c) = list(map(int, input().split()))
	(d, e, f) = list(map(int, input().split()))
	minimum = min(c, e)
	ans = minimum * 2
	c -= minimum
	e -= minimum
	minimum = min(d + e, b)
	b -= minimum
	print(ans - b * 2)
	_ -= 1


t = int(input())
for _ in range(t):
	(x_1, y_1, z_1) = [int(i) for i in input().split()]
	(x_2, y_2, z_2) = [int(i) for i in input().split()]
	sum_c = 0
	matched = min(x_1, z_2)
	x_1 -= matched
	z_2 -= matched
	matched = min(z_1, y_2)
	z_1 -= matched
	y_2 -= matched
	sum_c += 2 * matched
	matched = min(z_1, z_2)
	z_1 -= matched
	z_2 -= matched
	sum_c -= 2 * min(y_1, z_2)
	print(sum_c)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().strip().split())
	(x, y, z) = map(int, input().strip().split())
	pos = min(c, y)
	c -= pos
	y -= pos
	ans = 2 * pos
	if z - a - c > 0:
		ans -= 2 * (z - a - c)
	print(ans)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	(u, v, w) = map(int, ip().split())
	(x, y, z) = map(int, ip().split())
	ans = 0
	vx = min(v, x)
	v -= vx
	x -= vx
	uz = min(u, z)
	u -= uz
	z -= uz
	wy = min(w, y)
	w -= wy
	y -= wy
	ans += 2 * wy
	if v >= z:
		ans -= 2 * z
	else:
		ans -= 2 * v
	print(ans)


import sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	if x1 > 0 and z2 > 0:
		temp = min(x1, z2)
		x1 -= temp
		z2 -= temp
	if z1 > 0 and z2 > 0:
		temp = min(z1, z2)
		z1 -= temp
		z2 -= temp
	if z2 > 0:
		ans -= z2 * 2
	elif z1 > 0 and y2 > 0:
		temp = min(z1, y2)
		ans += temp * 2
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		a = LI()
		b = LI()
		t = min(a[0], b[2])
		a[0] -= t
		b[2] -= t
		t = min(a[2], b[2])
		a[2] -= t
		b[2] -= t
		t = min(a[1], b[2])
		r = t * -2
		t = min(a[2], b[1])
		r += t * 2
		rr.append(r)
	return JA(rr, '\n')
print(main())


import sys
import bisect
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ans = []
t = ini()
for _ in range(t):
	a = inl()
	b = inl()
	x = min(a[2], b[1])
	tmp = x * 2
	a[2] -= x
	b[1] -= x
	x = min(b[2], a[2] + a[0])
	b[2] = max(0, b[2] - x)
	a[2] = max(0, a[2] - x)
	tmp -= min(b[2], a[1]) * 2
	ans.append(tmp)
out(ans)


def seq(l1, l2):
	s = 0
	m1 = min(l1[0], l2[2])
	l1[0] -= m1
	l2[2] -= m1
	m2 = min(l1[1], l2[0])
	l1[1] -= m2
	l2[0] -= m2
	m3 = min(l1[2], l2[1])
	l1[2] -= m2
	l2[1] -= m2
	s += 2 * m3
	m4 = min(l1[1], l2[2])
	s -= 2 * m4
	print(s)
t = int(input())
l = []
for i in range(t):
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	l.append([s1, s2])
for j in l:
	seq(j[0], j[1])


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	sm = 0
	if c <= q:
		sm += 2 * c
		x = 0
		if r > a:
			x = r - a
		sm -= 2 * x
	else:
		sm += 2 * q
		x = 0
		if b > p:
			x = b - p
		sm -= 2 * x
	print(sm)


n = int(input())
for i in range(n):
	arr = [int(item) for item in input().split()]
	brr = [int(item) for item in input().split()]
	ans = 0
	flag = 0
	if arr[2] <= brr[1] and flag == 0:
		brr[1] = brr[1] - arr[2]
		ans = ans + 2 * arr[2]
		if arr[1] > brr[0] + brr[1]:
			arr[1] = arr[1] - brr[0] - brr[1]
			ans = ans - 2 * arr[1]
		flag = 1
	if arr[2] > brr[1] and flag == 0:
		arr[2] = arr[2] - brr[1]
		ans = ans + brr[1] * 2
		brr[1] = 0
		if arr[2] < brr[2]:
			brr[2] = brr[2] - arr[2]
			if arr[1] > brr[0]:
				arr[1] = arr[1] - brr[0]
				ans = ans - 2 * arr[1]
	print(ans)


t = int(input())
for test in range(t):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	ans = 0
	mini = min(z1, y2)
	ans += mini * 2
	z1 = z1 - mini
	y2 = y2 - mini
	mini = min(x1, z2)
	x1 = x1 - mini
	z2 = z2 - mini
	mini = min(z1, z2)
	z1 = z1 - mini
	z2 = z2 - mini
	ans -= min(z2, y1) * 2
	print(ans)


t = int(input())
for i in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	s = 0
	if a2 >= b1:
		s += b1 * 2
		a2 -= b1
		b1 = 0
	else:
		s += a2 * 2
		b1 -= a2
		a2 = 0
	if a2 >= b2:
		a2 -= b2
		b2 = 0
	else:
		b2 -= a2
		a2 = 0
	if a0 >= b2:
		a0 -= b2
		b2 = 0
	else:
		b2 -= a0
		a0 = 0
	cur = b0 + b1
	if a1 >= cur:
		a1 -= cur
	else:
		a1 = 0
	s -= min(a1, b2) * 2
	print(s)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(x, y, z) = I()
	(x1, y1, z1) = I()
	an = min(z, y1)
	z -= an
	y1 -= an
	an *= 2
	if z + x < z1:
		an -= (z1 - z - x) * 2
	print(an)


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


t = int(input())
for i in range(t):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	ans = 0
	k = min(c1, b2)
	ans += 2 * min(c1, b2)
	b2 -= k
	c1 -= k
	p = min(c2, c1)
	c1 -= p
	c2 -= p
	q = min(a1, c2)
	c2 -= q
	a1 -= q
	e = min(b1, b2)
	b1 -= e
	b2 -= e
	f = min(a2, b1)
	b1 -= f
	a2 -= f
	r = min(b1, c2)
	ans += -2 * r
	print(ans)


t = int(input())
sums = []
for _ in range(t):
	sum = 0
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	while z1 > 0 and y2 > 0:
		k = abs(z1 - y2)
		if z1 > y2:
			sum = sum + 2 * y2
			y2 = 0
			z1 = k
		else:
			sum = sum + 2 * z1
			z1 = 0
			y2 = k
	while z1 > 0 and z2 > 0:
		k = abs(z1 - z2)
		if z1 > z2:
			z2 = 0
			z1 = k
		else:
			z1 = 0
			z2 = k
	while z1 > 0 and x2 > 0:
		k = abs(z1 - x2)
		if z1 > x2:
			x2 = 0
			z1 = k
		else:
			z1 = 0
			x2 = k
	while y1 > 0 and y2 > 0:
		k = abs(y1 - y2)
		if y1 > y2:
			y2 = 0
			y1 = k
		else:
			y1 = 0
			y2 = k
	while y1 > 0 and x2 > 0:
		k = abs(y1 - x2)
		if y1 > x2:
			x2 = 0
			y1 = k
		else:
			y1 = 0
			x2 = k
	while y1 > 0 and z2 > 0:
		k = abs(y1 - z2)
		if y1 > z2:
			sum = sum - 2 * z2
			z2 = 0
			y1 = k
		else:
			sum = sum - 2 * y1
			y1 = 0
			z2 = k
	sums.append(sum)
for i in sums:
	print(i)


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	good = min(a[2], b[1])
	a[2] -= good
	ans += 2 * good
	b[1] -= good
	z = min(a[0], b[2])
	b[2] -= z
	a[0] -= z
	t = min(a[2], b[2])
	a[2] -= t
	b[2] -= t
	ans -= 2 * b[2]
	print(ans)
tt = int(input())
for test in range(tt):
	solve()


r = int(input())
for i in range(r):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	b2 = max(b2 - a0, 0)
	pos = min(a2, b1)
	a2 -= pos
	neg = max(min(b2 - a2, a1), 0)
	print(2 * (pos - neg))


from sys import stdin
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	s = 0
	if z1 > y2:
		s += 2 * y2
		z1 -= y2
		z2 -= z1
		if z2 > 0:
			z2 -= x1
		if z2 > 0 and z2 > y1:
			s -= y1 * 2
		elif z2 > 0:
			s -= z2 * 2
	else:
		s += 2 * z1
		y2 -= z1
		if z2 > x1:
			z2 -= x1
			y1 -= x2 + y2
			if y1 > 0:
				s -= min(y1, z2) * 2
	print(s)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	a = li()
	b = li()
	plus = min(a[2], b[1])
	ans = plus * 2
	a[2] -= plus
	b[1] -= plus
	zero1 = min(a[1], b[1])
	a[1] -= zero1
	b[1] -= zero1
	zero2 = min(a[2], b[2])
	a[2] -= zero2
	b[2] -= zero2
	zero = min(a[0], b[2])
	a[0] -= zero
	b[2] -= zero
	zero = min(a[2], b[0])
	a[2] -= zero
	b[0] -= zero
	zero = min(a[0], b[1])
	a[0] -= zero
	b[1] -= zero
	zero = min(a[1], b[0])
	a[1] -= zero
	b[0] -= zero
	ans -= a[1] * 2
	print(ans)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	a = []
	b = []
	c = []
	twos = min(z1, y2)
	z1 -= twos
	y2 -= twos
	if x2 + y2 >= y1:
		negtwos = 0
	else:
		negtwos = y1 - x2 - y2
	print(2 * twos - 2 * negtwos)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(x1, y1, z1) = RL()
		(x2, y2, z2) = RL()
		res = min(z1, y2) * 2
		res -= max(0, y1 - (y2 - min(z1, y2)) - x2) * 2
		print(res)
main()


import sys

def get_ints():
	return map(int, I().split())

def get_list():
	return list(map(int, I().split()))

def I():
	return sys.stdin.readline().strip()
for _ in range(int(I())):
	(a, b, c) = get_ints()
	(x, y, z) = get_ints()
	ans = 2 * min(c, y)
	c -= min(c, y)
	y -= min(c, y)
	z -= c
	z -= a
	ans -= 2 * max(0, z)
	print(ans)


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


for i in range(int(input())):
	(a1, a2, a3) = input().split()
	(b1, b2, b3) = input().split()
	(a1, a2, a3, b1, b2, b3) = (int(a1), int(a2), int(a3), int(b1), int(b2), int(b3))
	c = 0
	z = min(a3, b2)
	c += z * 2
	a3 = a3 - z
	b2 = b2 - z
	h = min(a1, b3)
	a1 = a1 - h
	b3 = b3 - h
	s = min(a3, b3)
	b3 = b3 - s
	a3 = a3 - s
	e = min(a2, b2)
	a2 = a2 - e
	b2 = b2 - e
	q = min(a2, b1)
	a2 = a2 - q
	b1 = b1 - q
	y = min(a1, b1)
	a1 = a1 - y
	b1 = b1 - y
	o = min(a2, b3)
	c -= 2 * o
	print(c)


num = int(input())
sums = [0] * num
for i in range(num):
	s = 0
	first = input()
	j = 0
	while True:
		if first[j] == ' ':
			x1 = int(first[0:j])
			break
		j += 1
	j += 1
	k = j
	while True:
		if first[j] == ' ':
			y1 = int(first[k:j])
			break
		j += 1
	z1 = int(first[j + 1:len(first)])
	first = input()
	j = 0
	while True:
		if first[j] == ' ':
			x2 = int(first[0:j])
			break
		j += 1
	j += 1
	k = j
	while True:
		if first[j] == ' ':
			y2 = int(first[k:j])
			break
		j += 1
	z2 = int(first[j + 1:len(first)])
	if z1 > y2:
		s += 2 * y2
		(z1, y2) = (z1 - y2, 0)
		if z2 > z1 + x1:
			z2 -= z1 + x1
			s -= 2 * z2
	if z1 <= y2:
		s += 2 * z1
		(z1, y2) = (0, y2 - z1)
		if z2 > x1:
			s -= 2 * (z2 - x1)
	sums[i] = s
for i in range(num):
	print(sums[i])


read = input
rn = lambda : list(map(int, read().split()))
T = rn()[0]
for i in range(T):
	(x1, y1, z1) = rn()
	(x2, y2, z2) = rn()
	S = 0
	p2 = min(y2, z1)
	y2 -= p2
	z1 -= p2
	S += 2 * p2
	tmp1 = x2 + y2 - y1
	tmp2 = x1 + z1 - z2
	if tmp1 > 0 or tmp2 > 0:
		print(S)
	else:
		print(S - 2 * min(abs(tmp1), abs(tmp2)))


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	sum = 2 * min(z1, y2)
	if z2 > x1:
		if z1 - y2 > 0:
			rem = z2 - x1 - (z1 - y2)
			if rem > 0:
				sum = sum - 2 * rem
		else:
			rem = z2 - x1
			sum = sum - 2 * rem
	print(sum)


import math

def function(x1, y1, z1, x2, y2, z2):
	y1 -= x2
	if y1 <= 0:
		print(2 * min(z1, y2))
	if y1 > 0:
		if y1 <= y2:
			c = y2 - y1
			print(2 * min(c, z1))
		if y1 > y2:
			y1 -= y2
			print(-2 * min(y1, z2))
t = int(input())
for k1 in range(t):
	(x1, y1, z1) = map(int, input().rstrip().split())
	(x2, y2, z2) = map(int, input().rstrip().split())
	function(x1, y1, z1, x2, y2, z2)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	if z1 >= y2:
		sum += 2 * y2
		z1 = z1 - y2
		if z2 > z1 + x1:
			sum -= 2 * max(z2 - z1 - x1, 0)
	else:
		sum += 2 * z1
		sum -= 2 * max(z2 - x1, 0)
	print(sum)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	l1 = zzz()
	l2 = zzz()
	t1 = min(l1[2], l2[1])
	ans = t1 * 2
	l1[2] -= t1
	l2[1] -= t1
	t2 = min(l2[2], l1[2])
	l1[2] -= t2
	l2[2] -= t2
	t3 = min(l2[2], l1[0])
	l2[2] -= t3
	l1[0] -= t3
	t4 = min(l2[2], l1[1])
	print(ans - t4 * 2)


def test():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	if z2 > x1:
		if z2 - x1 > z1:
			sum -= 2 * (z2 - x1 - z1)
		elif z1 - z2 + x1 > y2:
			sum += 2 * y2
		else:
			sum += 2 * (z1 - z2 + x1)
	elif z1 > y2:
		sum += 2 * y2
	else:
		sum += 2 * z1
	print(sum)
for _ in range(int(input())):
	test()


import sys, math, cmath, time
start_time = time.time()

def solve():
	(a, b, c) = invr()
	(x, y, z) = invr()
	q = min(c, y)
	c = c - q
	y = y - q
	q = q * 2
	if z > a + c:
		q = q - 2 * (z - a - c)
	print(q)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	if c <= e:
		if a >= f:
			print(2 * c)
		else:
			print(2 * c - 2 * (f - a))
	elif a + c - e >= f:
		print(2 * e)
	else:
		print(2 * e - 2 * (f - (a + c - e)))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	summ = 0
	if c <= y:
		summ += c * 2
		y -= c
		c = 0
	elif c > y:
		summ += y * 2
		c -= y
		y = 0
	if z > a + c:
		summ -= (z - (a + c)) * 2
	print(summ)


t = int(input())
while t > 0:
	t -= 1
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	print(min(c, e) * 2 - max(0, min(f - a - (c - min(c, e)), b)) * 2)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	su = 0
	mi = min(z1, y2)
	su += 2 * mi
	z1 -= mi
	y2 -= mi
	mi = min(z1, z2)
	z1 -= mi
	z2 -= mi
	mi = min(x1, z2)
	x1 -= mi
	z2 -= mi
	mi = min(z2, y1)
	su -= 2 * mi
	print(su)


for q in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	res = 0
	Y = min(y2, z1)
	res += Y * 2
	y2 -= Y
	z1 -= Y
	Y = min(z2, z1)
	z2 -= Y
	z1 -= Y
	Y = min(x1, z2)
	x1 -= Y
	z2 -= Y
	Y = min(y1, x2)
	y1 -= Y
	x2 -= Y
	Y = min(y1, y2)
	y1 -= Y
	y2 -= Y
	Y = min(y1, z2)
	res -= Y * 2
	print(res)


for j in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	t = 0
	if a >= z:
		z = 0
		a = a - z
		if c >= y:
			t = y * 2
		else:
			t = c * 2
	if a < z:
		z = z - a
		a = 0
		if c >= y:
			t = y * 2
			b = b - x
			if b > 0:
				t = t + b * -2
		if c < y:
			t = c * 2
			y = y - c
			b = b - (x + y)
			if b > 0:
				t = t + b * -2
	print(t)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = 0
	while x1 > 0 or y1 > 0 or z1 > 0 or (x2 > 0) or (y2 > 0) or (z2 > 0):
		if x1 >= z2:
			x1 = x1 - z2
			z2 = 0
		elif z2 > x1:
			z2 = z2 - x1
			x1 = 0
		if z1 >= y2:
			c = c + 2 * y2
			z1 = z1 - y2
			y2 = 0
		elif z1 < y2:
			c = c + 2 * z1
			y2 = y2 - z1
			z1 = 0
		if x1 <= x2:
			x2 = x2 - x1
			x1 = 0
		elif x1 > x2:
			x1 = x1 - x2
			x2 = 0
		if y1 <= y2:
			y2 = y2 - y1
			y1 = 0
		elif y1 > y2:
			y1 = y1 - y2
			y2 = 0
		if z1 <= z2:
			z2 = z2 - z1
			z1 = 0
		elif z1 > z2:
			z1 = z1 - z2
			z2 = 0
		a = z2 * 2
		c = c - a
		break
	print(c)


def ans(x1, y1, z1, x2, y2, z2):
	if y2 >= z1:
		ans = 2 * z1
		y2 -= z1
		z1 = 0
		if x1 >= z2:
			return ans
		else:
			z2 -= x1
			ans -= 2 * z2
			return ans
	else:
		ans = 2 * y2
		z1 -= y2
		y2 = 0
		if x1 + z1 >= z2:
			return ans
		else:
			z2 -= x1 + z1
			ans -= 2 * z2
			return ans
m = int(input())
for i in range(m):
	arr1 = input().split()
	arr2 = input().split()
	a1 = []
	a2 = []
	for i in arr1:
		a1.append(int(i))
	for i in arr2:
		a2.append(int(i))
	x1 = a1[0]
	y1 = a1[1]
	z1 = a1[2]
	x2 = a2[0]
	y2 = a2[1]
	z2 = a2[2]
	print(ans(x1, y1, z1, x2, y2, z2))


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	ans = 0
	m = min(f, a)
	f -= m
	a -= m
	m = min(b, d)
	b -= m
	d -= m
	m = min(c, e)
	c -= m
	e -= m
	ans += m * 2
	ans -= 2 * min(b, f)
	print(ans)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	tmp = min(a[2], b[1])
	ans += tmp * 2
	a[2] -= tmp
	b[1] -= tmp
	for i in range(2, -1, -1):
		if i == 0:
			for j in range(2, -1, -1):
				tmp = min(a[i], b[j])
				a[i] -= tmp
				b[j] -= tmp
			continue
		for j in range(i, -1, -1):
			tmp = min(a[i], b[j])
			a[i] -= tmp
			b[j] -= tmp
	if a[1] >= 1 and b[2] >= 1:
		ans -= min(a[1], b[2]) * 2
	print(ans)


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)


t = int(input())
b = []
a = []
for i in range(t):
	h = list(map(int, input().split()))
	l = list(map(int, input().split()))
	a.append(l)
	b.append(h)

def tully(x1, y1, z1, x2, y2, z2):
	su = 0
	k = min(z1, y2)
	su += 2 * k
	z1 = z1 - k
	y2 = y2 - k
	k2 = min(x1, z2)
	x1 = x1 - k2
	z2 = z2 - k2
	k3 = min(z1, z2)
	z1 = z1 - k3
	z2 = z2 - k3
	k4 = min(z1, x2)
	z1 = z1 - k4
	x2 = x2 - k4
	k5 = min(y1, y2)
	y1 = y1 - k5
	y2 = y2 - k5
	k6 = min(y1, x2)
	y1 = y1 - k6
	x2 = x1 - k6
	k7 = min(x1, x2)
	x1 = x1 - k7
	x2 = x2 - k7
	k8 = min(y2, x1)
	y2 = y2 - k8
	x1 = x1 - k8
	k9 = min(y1, z2)
	y1 = y1 - k9
	z2 = z2 - k9
	su -= 2 * k9
	return su
for i in range(t):
	y = tully(b[i][0], b[i][1], b[i][2], a[i][0], a[i][1], a[i][2])
	print(y)


from itertools import permutations
import math

def calculate(X, Y, o1, o2):
	i = 0
	j = 0
	ans = 0
	val1 = X[o1[i]]
	val2 = Y[o2[j]]
	while not (i == 2 and j == 2 and (val1 == val2) and (val1 == 0)):
		minval = min(val1, val2)
		if o1[i] > o2[j]:
			ans += o1[i] * o2[j] * minval
		elif o1[i] < o2[j]:
			ans -= o1[i] * o2[j] * minval
		val1 -= minval
		val2 -= minval
		if val1 == 0 and i < 2:
			i += 1
			val1 = X[o1[i]]
		if val2 == 0 and j < 2:
			j += 1
			val2 = Y[o2[j]]
	return ans
t = int(input())
for _ in range(t):
	x = list(map(int, input().strip().split()))
	y = list(map(int, input().strip().split()))
	ans = 0
	d = list(permutations(range(3)))
	n = len(d)
	ans = -math.inf
	for i in range(n):
		for j in range(n):
			ans = max(ans, calculate(x, y, d[i], d[j]))
	print(ans)


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


for i in range(int(input())):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	cnt = 0
	k = min(z1, y2)
	y2 -= k
	z1 -= k
	cnt = k * 2
	if x1 + z1 >= z2:
		print(cnt)
	else:
		cnt -= 2 * (z2 - x1 - z1)
		print(cnt)


for i in range(int(input())):
	(a0, a1, a2) = list(map(int, input().split()))
	(b0, b1, b2) = list(map(int, input().split()))
	ans = min(a2, b1)
	a2 -= ans
	b1 -= ans
	anm = min(a1, b0)
	a1 -= anm
	b0 -= anm
	app = min(b2, a0)
	b2 -= app
	a0 -= app
	sub = min(b2, a1)
	print((ans - sub) * 2)


for _ in range(int(input())):
	(x1, y1, z1) = list(map(lambda x: int(x), input().split()))
	(x2, y2, z2) = list(map(lambda x: int(x), input().split()))
	total = 0
	if z1 > 0:
		d = y2 - z1
		if d >= 0:
			total += 2 * z1
			y2 -= z1
			z1 = 0
		elif y2 > 0:
			total += 2 * y2
			z1 -= y2
			y2 = 0
	if z1 > 0:
		d = z2 - z1
		if d >= 0:
			z2 -= z1
			z1 = 0
		elif z2 > 0:
			z1 -= z2
			z2 = 0
	if z1 > 0:
		d = x2 - z1
		if d >= 0:
			x2 -= z1
			z1 = 0
		elif x2 > 0:
			z1 -= x2
			x2 = 0
	if y1 > 0:
		d = x2 - y1
		if d >= 0:
			x2 -= y1
			y1 = 0
		elif x2 > 0:
			y1 -= x2
			x2 = 0
	if y1 > 0:
		d = y2 - y1
		if d >= 0:
			y2 -= y1
			y1 = 0
		elif y2 > 0:
			y1 -= y2
			y2 = 0
	if y1 > 0:
		d = z2 - y1
		if d >= 0:
			z2 -= y1
			total += -1 * 2 * y1
			y1 = 0
		elif z2 > 0:
			total += -1 * 2 * z2
			y1 -= z2
			z2 = 0
	print(total)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	a1 = min(z1, y2) << 1
	temp = z1 - min(z1, y2)
	a1 -= max(z2 - temp - x1, 0) << 1
	a2 = max(z2 - z1 - x1, 0) << 1
	a2 *= -1
	if z2 < z1:
		a2 += min(z1 - z2, y2) << 1
	print(max(a1, a2))


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sumi = min(z1, y2) * 2
	gg = min(z1, y2)
	z1 = z1 - gg
	y2 = y2 - gg
	if x1 + z1 >= z2:
		print(sumi)
	else:
		z2 -= x1 + z1
		sumi -= z2 * 2
		print(sumi)


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(a, b, c, x, y, z):
	console('----- solving ------')
	score = min(c, y)
	remaining_non_1b = a + c - score
	remaining_non_2c = x + y - score
	remaining = a + b + c - score
	forced = remaining - remaining_non_1b - remaining_non_2c
	if forced <= 0:
		forced = 0
	console(remaining_non_1b, remaining_non_2c, remaining)
	console(score, forced)
	return (score - forced) * 2

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	res = solve(a, b, c, x, y, z)
	print(res)


for _ in range(int(input())):
	(x1, x2, x3) = list(map(int, input().split()))
	(y1, y2, y3) = list(map(int, input().split()))
	s = 0
	count = min(x3, y2)
	x3 -= count
	s += count * 2
	y3 -= x1 + x3
	if y3 > 0:
		s -= min(x2, y3) * 2
	print(s)


T = int(input())

def x(res, a, b, i, j):
	val = min(a[i], b[j])
	if i == 2 and j == 1:
		res += 2 * val
	elif i == 1 and j == 2:
		res -= 2 * val
	a[i] -= val
	b[j] -= val
	return res
for _ in range(T):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 0
	res = x(res, a, b, 2, 1)
	res = x(res, a, b, 2, 2)
	res = x(res, a, b, 2, 0)
	res = x(res, a, b, 1, 0)
	res = x(res, a, b, 1, 1)
	res = x(res, a, b, 0, 1)
	res = x(res, a, b, 0, 2)
	res = x(res, a, b, 0, 0)
	res = x(res, a, b, 1, 2)
	print(res)


import math
for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	m = min(a2, b1)
	summ = 2 * m
	b1 -= m
	a2 -= m
	m = min(a0, b2)
	a0 -= m
	b2 -= m
	m = min(a1, b0)
	a1 -= m
	b0 -= m
	summ -= 2 * min(a1, b2)
	print(summ)


for _ in range(int(input())):
	(z1, o1, t1) = list(map(int, input().split()))
	(z2, o2, t2) = list(map(int, input().split()))
	ans = 0
	ans += 2 * min(t1, o2)
	t1 -= min(t1, o2)
	o2 -= min(t1, o2)
	t2 -= min(t2, z1)
	t2 -= min(t2, t1)
	ans -= 2 * min(t2, o1)
	print(ans)


n = int(input())
while n > 0:
	n -= 1
	(l, m, k) = map(int, input().split())
	(l2, m2, k2) = map(int, input().split())
	ans = 0
	if k >= m2:
		ans += 2 * m2
	else:
		ans += 2 * k
	k = max(0, k - m2)
	k2 = max(0, k2 - l)
	k2 = max(0, k2 - k)
	if k2 >= m:
		ans -= 2 * m
	else:
		ans -= 2 * k2
	print(ans)


def sol(x, y, z, a, b, c):
	hash1 = [x, y, z]
	hash2 = [a, b, c]
	score = 0
	m = min(hash1[2], hash2[1])
	hash1[2] -= m
	hash2[1] -= m
	score += 2 * m
	if hash1[2]:
		m = min(hash2[2], hash1[2])
		hash1[2] -= m
		hash2[2] -= m
		if hash1[2]:
			m = min(hash1[2], hash2[0])
			hash1[2] -= m
			hash2[0] -= m
	if hash1[1]:
		m = min(hash1[1], hash2[1])
		hash1[1] -= m
		hash2[1] -= m
		m = min(hash2[0], hash1[1])
		hash1[1] -= m
		hash2[0] -= m
		score -= 2 * min(hash1[1], hash2[2])
	print(score)
k = int(input())
for i in range(k):
	(x, y, z) = list(map(int, input().split(' ')))
	(a, b, c) = list(map(int, input().split(' ')))
	sol(x, y, z, a, b, c)


try:
	t = int(input())
	for i in range(t):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		if z1 == min(z1, y2):
			val = z1 * 2
			y2 = y2 - z1
			if y1 <= y2 + x2:
				print(val)
			else:
				y1 -= y2 + x2
				val -= y1 * 2
				print(val)
		else:
			val = y2 * 2
			z1 = z1 - y2
			if y1 <= x2:
				print(val)
			else:
				y1 = y1 - x2
				val -= y1 * 2
				print(val)
except:
	pass


for t in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	s = 0
	z22 = z2 - x1
	if z22 > 0:
		z11 = z1 - z22
		z22 = z22 - z1
		if z22 > 0:
			print(-2 * min(y1, z22))
		else:
			print(2 * min(y2, z11))
	else:
		print(2 * min(z1, y2))


a = int(input())
for i in range(a):
	(x1, y1, z1) = list(map(lambda x: int(x), input().split()))
	(x2, y2, z2) = list(map(lambda x: int(x), input().split()))
	summa = 0
	if z1 > 0 and y2 > 0:
		if z1 > y2:
			summa += 2 * y2
			z1 = z1 - y2
			y2 = 0
		elif z1 < y2:
			summa += 2 * z1
			y2 = y2 - z1
			z1 = 0
		else:
			summa += 2 * z1
			z1 = 0
			y2 = 0
	if z2 > 0 and x1 > 0:
		if z2 > x1:
			z2 = z2 - x1
			x1 = 0
		elif z2 < x1:
			z2 = 0
			x1 = x1 - z2
		else:
			z2 = 0
			x1 = 0
	if z2 > 0 and z1 > 0:
		if z2 > z1:
			z2 = z2 - z1
			z1 = 0
		elif z2 < z1:
			z2 = 0
			z1 = z1 - z2
		else:
			z2 = 0
			z1 = 0
	if z2 > 0 and y1 > 0:
		if z2 > y1:
			summa -= 2 * y1
		elif z2 < y1:
			summa -= 2 * z2
		else:
			summa -= 2 * z2
	print(summa)


def max_c(x, y, z, a, b, c):
	if c < x:
		return 2 * min(z, b)
	if c < x + z:
		return 2 * min(x + z - c, b)
	return -2 * (c - x - z)
for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	print(max_c(x, y, z, a, b, c))


import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

def lii():
	return list(map(int, input().split()))

def ii():
	return int(input())
t = ii()
for _ in range(t):
	(x1, y1, z1) = lii()
	(x2, y2, z2) = lii()
	res = 0
	temp = min(z1, y2)
	res += 2 * temp
	z1 -= temp
	y2 -= temp
	temp = min(z1 + x1, z2)
	z2 -= temp
	res -= 2 * z2
	print(res)


import sys
import collections

def input():
	return sys.stdin.readline().rstrip()

def split_input():
	return [int(i) for i in input().split()]
tests = int(input())
for _ in range(tests):
	(x1, y1, z1) = split_input()
	(x2, y2, z2) = split_input()
	ans = 0
	if z1 <= y2:
		ans += z1 * 2
		z1 = 0
	else:
		ans += y2 * 2
		z1 -= y2
	if z1 >= z2:
		print(ans)
		continue
	z2 -= z1
	if z2 <= x1:
		print(ans)
		continue
	z2 -= x1
	ans -= 2 * z2
	print(ans)


test_cases = int(input())
for _ in range(test_cases):
	(x1, y1, z1) = [int(i) for i in input().split(' ')]
	(x2, y2, z2) = [int(i) for i in input().split(' ')]
	aux = 0 if y2 <= z1 else y2 - z1
	print(2 * min(z1, y2) - (0 if y1 <= x2 + aux else 2 * (y1 - x2 - aux)))


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


import math
tests = int(input())
for t in range(tests):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = min(z1, y2) * 2
	a = min(z1, y2)
	z1 -= a
	y2 -= a
	b = min(z1, z2)
	z1 -= b
	z2 -= b
	c = min(y1, x2)
	y1 -= c
	x2 -= c
	d = min(y1, y2)
	y1 -= d
	y2 -= d
	e = min(z1, x2)
	z1 -= e
	x2 -= e
	f = min(x1, z2)
	z2 -= f
	x1 -= f
	ans -= min(y1, z2) * 2
	y1 -= min(y1, z2)
	z2 -= min(y1, z2)
	print(ans)


def solve(x, y, sum_, num):
	inc = min(x, y)
	sum_ += inc * num
	x -= inc
	y -= inc
	return (x, y, sum_)
T = int(input())
for _ in range(T):
	(x1, y1, z1) = [int(x) for x in input().split(' ')]
	(x2, y2, z2) = [int(x) for x in input().split(' ')]
	sum_ = 0
	if z1 != 0 and y2 != 0:
		(z1, y2, sum_) = solve(z1, y2, sum_, 2)
	if z1 != 0 and z2 != 0:
		(z1, z2, sum_) = solve(z1, z2, sum_, 0)
	if y1 != 0 and x2 != 0:
		(y1, x2, sum_) = solve(y1, x2, sum_, 0)
	if y1 != 0 and y2 != 0:
		(y1, y2, sum_) = solve(y1, y2, sum_, 0)
	if y1 != 0 and z2 != 0:
		(y1, z2, sum_) = solve(y1, z2, sum_, -2)
	print(sum_)


t = int(input())
while t:
	(a0, a1, a2) = list(map(int, input().split()))
	(b0, b1, b2) = list(map(int, input().split()))
	ans = 0
	tmp = min(b2, a0)
	b2 -= tmp
	a0 -= tmp
	tmp = min(a1, b0)
	a1 -= tmp
	b0 -= tmp
	tmp = min(a2, b1)
	ans += 2 * tmp
	tmp = min(a1, b2)
	ans -= 2 * tmp
	print(ans)
	t -= 1


def findMaxSum(x1, y1, z1, x2, y2, z2):
	sum = 0
	pairs21 = min(z1, y2)
	sum += 2 * pairs21
	z1 = z1 - pairs21
	y2 = y2 - pairs21
	if y1 > x2 + y2:
		y1 = y1 - (x2 + y2)
	else:
		return sum
	if z2 > x1 + z1:
		z2 = z2 - (x1 + z1)
	else:
		return sum
	sum = sum - 2 * z2
	return sum
t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	print(findMaxSum(x1, y1, z1, x2, y2, z2))


from sys import stdin, stdout
t = int(stdin.readline())
for case in range(t):
	(ai, bi, ci) = map(int, stdin.readline().split())
	(aj, bj, cj) = map(int, stdin.readline().split())
	ans = 0
	mnm = min(bi, aj)
	bi -= mnm
	aj -= mnm
	mnm = min(ai, cj)
	ai -= mnm
	cj -= mnm
	mnm = min(ci, bj)
	ans += 2 * mnm
	ci -= mnm
	bj -= mnm
	mnm = min(cj, bi)
	ans -= 2 * mnm
	stdout.write('{}\n'.format(ans))


t = int(input())
for h in range(t):
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	ans = 0
	m1 = min(lis1[2], lis2[1])
	lis1[2] = lis1[2] - m1
	lis2[1] = lis2[1] - m1
	ans = ans + m1 * 2
	m2 = min(lis1[0], lis2[2])
	lis1[0] = lis1[0] - m2
	lis2[2] = lis2[2] - m2
	m3 = min(lis1[2], lis2[2])
	lis1[2] = lis1[2] - m3
	lis2[2] = lis2[2] - m3
	if lis2[2] == 0:
		print(ans)
	elif lis1[1] == 0:
		print(ans)
	else:
		m4 = min(lis1[1], lis2[2])
		ans = ans - m4 * 2
		print(ans)


import sys

def solve(w1, w2):
	(x1, y1, z1) = w1
	(x2, y2, z2) = w2
	ans = 0
	if z1 >= y2:
		ans += 2 * y2
		if z1 - y2 + x1 < z2:
			ans -= 2 * (z2 - (z1 - y2 + x1))
	else:
		ans += 2 * z1
		if x1 < z2:
			ans -= 2 * (z2 - x1)
	print(ans)
	sys.stdout.flush()
T = int(input())
for t in range(T):
	w1 = [int(it) for it in input().split(' ')]
	w2 = [int(it) for it in input().split(' ')]
	solve(w1, w2)


t = int(input())
while t > 0:
	(z1, y1, x1) = map(int, input().split())
	(z2, y2, x2) = map(int, input().split())
	(z1, x2) = (z1 - min(z1, x2), x2 - min(z1, x2))
	(x1, x2) = (x1 - min(x1, x2), x2 - min(x1, x2))
	a = 2 * min(x1, y2) - 2 * min(x2, y1)
	print(a)
	t -= 1


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if max(x1, z2) == x1:
		print(min(z1, y2) * 2)
	else:
		z2 -= x1
		if max(z1, z2) == z1:
			z1 -= z2
			print(min(z1, y2) * 2)
		else:
			z2 -= z1
			print(min(z2, y1) * -2)


T = int(input())
for t in range(1, T + 1):
	(x1, y1, z1) = [int(inp) for inp in input().split()]
	(x2, y2, z2) = [int(inp) for inp in input().split()]
	n = x1 + y1 + z1
	plus = min(z1, y2)
	minus = max(0, plus + z2 + y1 - n)
	ans = 2 * (plus - minus)
	print(str(ans))


I = input
for _ in [0] * int(I()):
	(a, b, c, d, e, f) = map(int, (I() + ' ' + I()).split())
	print(min(c, e, d + e - b) * 2)


def solve(x1, y1, z1, x2, y2, z2):
	result = 0
	if z1 >= y2:
		result += 2 * y2
		z1 = z1 - y2
		y2 = 0
	elif z1 < y2:
		result += 2 * z1
		y2 = y2 - z1
		z1 = 0
	if z2 <= x1:
		x1 = x1 - z2
		z2 = 0
	elif z2 > x1:
		z2 = z2 - x1
		x1 = 0
		if z1 >= z2:
			z1 = z1 - z2
			z2 = 0
		else:
			z2 = z2 - z1
			z1 = 0
			result -= 2 * z2
	return result
for _ in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	print(solve(x1, y1, z1, x2, y2, z2))


from collections import Counter

def main():
	for _ in range(Iint()):
		(x0, x1, x2) = Ilist()
		(y0, y1, y2) = Ilist()
		m = min(x0, y2)
		x0 -= m
		y2 -= m
		m = min(x1, y0)
		x1 -= m
		y0 -= m
		m = min(x2, y1)
		x2 -= 1
		y1 -= 1
		sum_output = 2 * m
		sum_output -= 2 * min(x1, y2)
		print(sum_output)

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
main()


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	(x, y, z) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	py = min(p, y)
	y -= py
	rx = min(r, x)
	r -= rx
	res = min(z, q) * 2 - min(y, r) * 2
	print(res)


t = int(input())
for i in range(t):
	inp = input().split(' ')
	out = input().split(' ')
	x1 = int(inp[0])
	x2 = int(inp[1])
	x3 = int(inp[2])
	y1 = int(out[0])
	y2 = int(out[1])
	y3 = int(out[2])
	ans = 0
	two = min(x3, y2)
	x3 = x3 - two
	y2 = y2 - two
	if x3 > 0:
		a = min(x3, y3)
		x3 = x3 - a
		y3 = y3 - a
	zero = min(y3, x1)
	y3 = y3 - zero
	x1 = x1 - zero
	equa = min(y2, x2)
	x2 = x2 - equa
	y2 = y2 - equa
	equa = min(y1, x2)
	x2 = x2 - equa
	y1 = y1 - equa
	equa = min(y2, x1)
	y2 = y2 - equa
	x1 = x1 - equa
	equa = min(x1, y1)
	x1 = x1 - equa
	y1 = y1 - equa
	if x3 > 0:
		a = min(x3, y1)
		x3 = x3 - a
		y1 = y1 - a
	nega = min(y3, x2)
	ans = ans + two * 2
	ans = ans - 2 * nega
	print(ans)


t = int(input())
ans = []
for _ in range(t):
	[x1, y1, z1] = list(map(int, input().split()))
	[x2, y2, z2] = list(map(int, input().split()))
	if x1 >= z2:
		ans.append(2 * min(z1, y2))
	elif z2 > x1 + z1:
		ans.append(-2 * (z2 - x1 - z1))
	else:
		ans.append(2 * min(z1 - z2 + x1, y2))
for x in ans:
	print(x)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c1 = min(z1, y2)
	z1 = z1 - c1
	d1 = min(z2, x1 + z1)
	z2 = z2 - d1
	c = c1 * 2 - 2 * min(z2, y1)
	print(c)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(m,) = I()
while m:
	m -= 1
	(a, b, c) = I()
	(x, y, z) = I()
	if a >= z:
		print(2 * min(c, y))
	elif a + c == z:
		print(0)
	elif a + c > z:
		print(2 * min(y, c - (z - a)))
	else:
		print(2 * (a + c - z))


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	gh = min(z1, y2)
	ans = 2 * min(z1, y2)
	z1 = z1 - gh
	y2 = y2 - gh
	if z1 == 0:
		if z2 > x1:
			ans += -2 * (z2 - x1)
		else:
			ans += 0
	elif z2 > z1 + x1:
		ans += -2 * (z2 - z1 - x1)
	else:
		ans += 0
	print(ans)


t = int(input())
for hh in range(0, t):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(x2, y2, z2) = [int(x) for x in input().split()]
	ans = 0
	mn2 = min(z1, y2)
	ans += mn2 * 2
	startrem = 0
	if y2 < z1:
		startrem = z1 - y2
	if x1 + startrem < z2:
		rem = z2 - x1 - startrem
		mn2 = min(rem, y1)
		ans -= mn2 * 2
	print(ans)


for _ in ' ' * int(input()):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = map(int, input().split())
	k = min(c1, a)
	c1 -= k
	a -= k
	k = min(b, a1)
	b -= k
	a1 -= k
	print(2 * (min(b1, c) - min(c1, b)))


t = int(input())
for q in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	total = 0
	if z1 >= y2:
		total += y2 * 2
		z1 = z1 - y2
		y2 = 0
	else:
		total += z1 * 2
		z1 = 0
		y2 = y2 - z1
	if z2 > x1 + z1:
		z2 = z2 - (x1 + z1)
		total = total - z2 * 2
	print(total)


import io, os
from collections import deque
import bisect
RL = lambda : list(map(int, input().split(' ')))
T = int(input())
for _ in range(T):
	(x1, y1, z1) = RL()
	(x2, y2, z2) = RL()
	ans = 2 * min(z1, y2) - 2 * max(y1 - (max(y2 - z1, 0) + x2), 0)
	print(ans)
	remo = max(y1 - (max(y2 - z1, 0) + x2), 0)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a0 = a[0]
	a1 = a[1]
	a2 = a[2]
	b0 = b[0]
	b1 = b[1]
	b2 = b[2]
	s = 0
	mini = min(a2, b1)
	s += 2 * mini
	a2 -= mini
	b1 -= mini
	mini2 = min(a1, b1 + b0)
	a1 -= mini2
	s -= 2 * a1
	print(s)


import sys
readline = sys.stdin.buffer.readline

def i1():
	return int(readline())

def nl():
	return [int(s) for s in readline().split()]

def nlp(x):
	return [int(s) + x for s in readline().split()]

def nll(n):
	return [[int(s) for s in readline().split()] for i in range(n)]

def mll(n):
	return ([int(s) for s in readline().split()] for i in range(n))

def s1():
	return readline().rstrip()

def sn(n):
	return [readline().rstrip() for i in range(n)]

def sm(n):
	return (readline().rstrip() for i in range(n))

def redir(s):
	global readline
	import os
	fn = sys.argv[0] + f'/../in-{s}.txt'
	readline = open(fn).readline if os.path.exists(fn) else readline
redir('b')
t = i1()
for i in range(t):
	a = nl()
	b = nl()
	if b[2] > a[0]:
		b[2] -= a[0]
		if b[2] > a[2]:
			b[2] -= a[2]
			print(-2 * b[2])
			continue
		else:
			a[2] -= b[2]
	print(2 * min(a[2], b[1]))


def main():
	t = int(input())
	for case in range(t):
		a = [int(x) for x in input().split()]
		b = [int(x) for x in input().split()]
		(x1, y1, z1) = (a[0], a[1], a[2])
		(x2, y2, z2) = (b[0], b[1], b[2])
		sum = 0
		if z2 > x1:
			z2 -= x1
			x1 -= x1
		else:
			x1 -= z2
			z2 -= z2
		if z2 > 0:
			if z2 > z1:
				z2 -= z1
				z1 -= z1
			else:
				z1 -= z2
				z2 -= z2
		if z2 > 0:
			sum -= 2 * z2
			y1 -= z2
			z2 -= z2
		if z1 > 0:
			if y2 > z1:
				sum += 2 * z1
				y2 -= z1
				z1 -= z1
			else:
				sum = 2 * y2
		print(sum)
main()


for t in range(int(input())):
	(x1, y1, z1) = [int(x) for x in input().split(' ')]
	(x2, y2, z2) = [int(y) for y in input().split(' ')]
	c2 = min(z1, y2)
	z1 = z1 - c2
	y2 = y2 - c2
	y1 = y1 - min(y1, x2 + y2)
	print(2 * c2 - 2 * y1)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for _ in range(ii()):
		(x1, y1, z1) = mi()
		(x2, y2, z2) = mi()
		m = min(z1, y2)
		z1 -= m
		y2 -= m
		s = 2 * m
		z2 -= z1
		m2 = min(z2, x1)
		z2 -= m2
		s -= 2 * min(z2, y1)
		print(s)
main()


t = int(input())
for k in range(t):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	s = 0
	m = min(a[2], b[1])
	a[2] -= m
	b[1] -= 1
	s += 2 * m
	m = min(a[0], b[2])
	a[0] -= m
	b[2] -= m
	m = min(a[1], b[0])
	a[1] -= m
	b[0] -= m
	s -= 2 * min(a[1], b[2])
	print(s)


for _ in range(int(input())):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	x = min(a1, c2)
	a1 -= x
	c2 -= x
	x = min(b1, a2)
	b1 -= x
	a2 -= x
	x = min(c1, b2)
	c1 -= x
	b2 -= x
	s = 2 * x
	s -= 2 * min(c2, b1)
	print(s)


import sys
import string
import math
import heapq
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def solve(a0, a1, a2, b0, b1, b2):
	matched = min(a2, b1)
	a2 -= matched
	b1 -= matched
	tot = matched * 2
	matched = min(b2, a0)
	a0 -= matched
	b2 -= matched
	matched = min(b2, a2)
	b2 -= matched
	a2 -= matched
	matched = min(a1, b2)
	tot -= matched * 2
	print(tot)

def main():
	t = iline()
	for _ in range(t):
		solve(*mi(line()), *mi(line()))
main()


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = min(z1, y2)
	z1 -= c
	y2 -= c
	res = c * 2
	if x1 + z1 < z2:
		res -= (z2 - x1 - z1) * 2
	print(res)


for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 2 * min(a2, b1)
	if a0 < b2:
		diff = 2 * min(a1, b2 - a0 - max(0, a2 - b1))
		diff = max(0, diff)
		ans -= diff
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	s = 2 * min(c, e)
	e = max(e - c, 0)
	x = max(b - (d + e), 0) * 2
	print(s - x)


t = int(input())
while t:
	t -= 1
	(x1, y1, z1) = [int(ai) for ai in input().split()]
	(x2, y2, z2) = [int(ai) for ai in input().split()]
	ans = min(z1, y2)
	z1 -= ans
	y2 -= ans
	y1 -= min(y1, x2)
	z2 -= min(z2, x1)
	y1 -= min(y1, y2)
	z2 -= min(z2, z1)
	ans -= min(y1, z2)
	print(2 * ans)


for _ in range(0, int(input())):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = l1[2]
	b = l1[1]
	c = l1[0]
	x = l2[2]
	y = l2[1]
	z = l2[0]
	ans = 0
	ay = min(a, y)
	ans += ay * 2
	a -= ay
	y -= ay
	xc = min(x, c)
	x -= xc
	c -= xc
	ax = min(x, a)
	x -= ax
	a -= xc
	bx = min(b, x)
	ans -= 2 * bx
	print(ans)


for testcases in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 2 * min(a2, b1)
	nic = 0
	if a2 > b1:
		nic = a2 - b1
	if b2 > a0 + nic:
		flag = b2 - a0 - nic
		ans -= 2 * min(flag, a1)
	print(ans)


from collections import defaultdict
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	ans = 0
	if x2 > y1:
		ans += y1 * 2
		x2 -= y1
		y1 = 0
		if x2 > y2:
			x2 -= y2
			y2 = 0
		else:
			y2 -= x2
			x2 = 0
			if x0 > y2:
				y2 = 0
			else:
				y2 -= x0
				x0 = 0
				ans -= 2 * y2
	else:
		ans += x2 * 2
		y1 -= x2
		x2 = 0
		if x0 > y2:
			y2 = 0
		else:
			y2 -= x0
			x0 = 0
			ans -= y2 * 2
	print(ans)


for cases in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum1 = 0
	min1 = min(a[2], b[1])
	sum1 += min1 * 2
	b[2] = b[2] - (a[2] - min1)
	if a[0] > 0:
		b[2] = b[2] - a[0]
	if b[2] > 0:
		if a[1] > 0:
			sum1 = sum1 - 2 * b[2]
	print(sum1)


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


for _ in range(int(input())):
	(zero_a, one_a, two_a) = map(int, input().split(' '))
	(zero_b, one_b, two_b) = map(int, input().split(' '))
	ans = 0
	x1 = min(zero_a, two_b)
	zero_a = zero_a - x1
	two_b = two_b - x1
	x2 = min(one_a, zero_b)
	one_a = one_a - x2
	zero_b = zero_b - x2
	x3 = min(two_a, one_b)
	ans = ans + 2 * x3
	two_a = two_a - x3
	one_b = one_b - x2
	ans = ans - 2 * min(one_a, two_b)
	print(ans)


def getArrayInt():
	inp = input().split()
	inp = [int(x) for x in inp]
	return inp
t = int(input())
mn = 1
while mn <= t:
	input1 = getArrayInt()
	input2 = getArrayInt()
	(x1, y1, z1) = (input1[0], input1[1], input1[2])
	(x2, y2, z2) = (input2[0], input2[1], input2[2])
	max_positive = min(z1, y2) * 2
	z1 -= min(z1, y2)
	y2 -= min(z1, y2)
	z2 -= z1
	z2 -= min(z2, x1)
	max_negative = min(z2, y1) * 2
	print(max_positive - max_negative)
	mn += 1


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(a0, a1, a2) = map(int, stdin.readline().split(' '))
	(b0, b1, b2) = map(int, stdin.readline().split(' '))
	ans = 0
	t1 = min(a2, b1)
	ans += 2 * t1
	a2 -= t1
	b1 -= t1
	if b2 != 0:
		t1 = min(a0, b2)
		a0 -= t1
		b2 -= t1
		if b2 != 0:
			t1 = min(a2, b2)
			a2 -= t1
			b2 -= t1
			if b2 != 0:
				t1 = min(a1, b2)
				a1 -= t1
				b2 -= t1
				ans -= 2 * t1
	stdout.write(str(ans) + '\n')


a = input()
for x in range(int(a)):
	c = input().split(' ')
	d = input().split(' ')
	list1 = [int(i) for i in c]
	list2 = [int(i) for i in d]
	ans = list1[2] - max(list2[2] - list1[0], 0)
	if ans <= 0:
		print(ans * 2)
	else:
		print(min(ans, list2[1]) * 2)


for _ in range(int(input())):
	X = list(map(int, input().split()))
	Y = list(map(int, input().split()))
	n1 = min(X[2], Y[1])
	n2 = 0
	z = X[2] - n1
	if Y[2] > X[0] + z:
		n2 = Y[2] - X[0] - z
	ans = 2 * n1 - 2 * n2
	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 _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	total = 0
	q = min(a[2], b[1])
	total += 2 * q
	a[2] -= q
	b[1] -= q
	q = min(a[2], b[2])
	a[2] -= q
	b[2] -= q
	q = min(a[1], b[1])
	a[1] -= q
	b[1] -= q
	q = min(a[1], b[0])
	a[1] -= q
	b[0] -= q
	q = min(a[0], b[0])
	a[0] -= q
	b[0] -= q
	q = min(a[2], b[0])
	a[2] -= q
	b[0] -= q
	q = min(a[0], b[1])
	a[0] -= q
	b[1] -= q
	q = min(a[0], b[2])
	a[0] -= q
	b[2] -= q
	q = min(a[1], b[1])
	total -= q
	a[1] -= q
	b[1] -= q
	q = min(a[1], b[2])
	total -= 2 * q
	a[1] -= q
	b[2] -= q
	print(total)


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = min(z1, y2)
	z1 -= ans
	y2 -= ans
	print(ans * 2 - min(max(y1 - (x2 + y2), 0), max(z2 - (x1 + z1), 0)) * 2)


t = int(input())
while t:
	t -= 1
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if z1 > y2:
		s = y2 * 2
		if z1 - y2 + x1 < z2:
			s -= (z2 - z1 + y2 - x1) * 2
	else:
		s = z1 * 2
		if x1 < z2:
			s -= (z2 - x1) * 2
	print(s)


import sys
t = int(input())
while t:
	t -= 1
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	pans = 2 * min(a2, b1)
	nans = 0
	if a2 > b1:
		l2 = a2 - b1
		nb2 = l2 + a0 - b2
		if nb2 < 0:
			nans = 2 * abs(nb2)
	else:
		nb2 = a0 - b2
		if nb2 < 0:
			nans = 2 * abs(nb2)
	print(pans - nans)


output = []
for i in range(int(input())):
	z = 0
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	c = int(x[2])
	x = input().split()
	d = int(x[0])
	e = int(x[1])
	f = int(x[2])
	g = min(c, e)
	c -= g
	e -= g
	z += g * 2
	g = min(c, f)
	c -= g
	f -= g
	g = min(f, a)
	a -= g
	f -= g
	z -= min(b, f) * 2
	output.append(z)
print('\n'.join([str(i) for i in output]))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(x0, x1, x2) = ria()
		(y0, y1, y2) = ria()
		sum = 0
		m = min(x0, y2)
		x0 -= m
		y2 -= m
		m = min(x1, y0)
		x1 -= m
		y0 -= m
		m = min(x2, y1)
		x2 -= m
		y1 -= m
		sum += 2 * m
		sum -= 2 * min(x1, y2)
		print(sum)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	hashm = {}
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		[a0, a1, a2] = inlt()
		[b0, b1, b2] = inlt()
		ans = 0
		if a2 >= b1:
			ans = ans + 2 * b1
			a2 = a2 - b1
			b1 = 0
			if b2 >= a2:
				b2 = b2 - a2
				a2 = 0
			else:
				a2 = a2 - b2
				b0 = b0 - a2
				b2 = 0
		else:
			ans = ans + 2 * a2
			b1 = b1 - a2
			a2 = 0
		if a1 >= b1:
			a1 = a1 - b1
			if a1 > b0:
				a1 = a1 - b0
				ans = ans - 2 * a1
		print(ans)
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a0, a1, a2) = [int(x) for x in input().split()]
	(b0, b1, b2) = [int(x) for x in input().split()]
	count = 0
	count += 2 * min(a2, b1)
	temp = min(a2, b1)
	a2 = a2 - temp
	b1 = b1 - temp
	if b2 - a0 - a2 > 0:
		t = min(b2 - a0 - a2, a1)
		count -= 2 * t
	print(count)


def main():
	t = int(input())
	for _ in range(t):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		total = 0
		m = min(z1, y2)
		z1 -= m
		y2 -= m
		total += 2 * m
		y1 -= x2 + y2
		if y1 > 0:
			total -= y1 * 2
		print(total)
main()


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	ans = 0
	temp = min(c, q)
	ans += 2 * temp
	c -= temp
	q -= temp
	temp = min(c, r)
	c -= temp
	r -= temp
	temp = min(a, r)
	a -= temp
	r -= temp
	ans -= 2 * r
	print(ans)


t = int(input())
for i in range(0, t):
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	result = 0
	ops = [(0, 2), (2, 2), (1, 2), (2, 1), (1, 1)]
	for (i, j) in ops:
		count = min(a[i], b[j])
		a[i] -= count
		b[j] -= count
		if i > j:
			result += count * (i * j)
		elif i < j:
			result += -1 * count * (i * j)
	print(result)


def getThree():
	(a, b, c) = map(int, input().split())
	return [a, b, c]

def f(a, b):
	if a < b:
		return -a * b
	elif a == b:
		return 0
	else:
		return a * b

def min(a, b):
	if a < b:
		return a
	return b
priperty = [[2, 1], [1, 0], [0, 0], [2, 0], [1, 1], [0, 2], [2, 2], [0, 1], [1, 2]]

def main():
	from collections import Counter
	t = int(input())
	for _ in range(t):
		a = getThree()
		b = getThree()
		ans = 0
		for (ix, iy) in priperty:
			cnt = min(a[ix], b[iy])
			ans += cnt * f(ix, iy)
			a[ix] -= cnt
			b[iy] -= cnt
		print(ans)
main()


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	c = 0
	c = min(z, y1)
	z -= c
	y1 -= c
	m = min(z1, x)
	z1 -= m
	x -= m
	m = min(z1, z)
	z1 -= m
	z -= m
	m = min(y, x1)
	y -= m
	x1 -= m
	m = min(y, y1)
	y -= m
	y1 -= m
	m = min(y, z1)
	c *= 2
	c -= m * 2
	print(c)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(a, b, c) = MI()
	(x, y, z) = MI()
	temp = min(c, y)
	ans = 2 * temp
	c -= temp
	y -= temp
	temp = min(c, z)
	c -= temp
	z -= temp
	temp = min(a, z)
	a -= temp
	z -= temp
	temp = min(a, y)
	a -= temp
	y -= temp
	temp = min(b, x + y)
	b -= temp
	temp = min(z, a)
	z -= temp
	a -= temp
	ans -= min(b, z) * 2
	print(ans)


t = int(input())
for oo in range(t):
	(a, b, c) = [int(xx) for xx in input().split()]
	(x, y, z) = [int(xx) for xx in input().split()]
	k = 2 * min(c, y)
	if c > y:
		c -= y
		if z >= c:
			z -= c
			c = 0
		else:
			x -= c - z
			c = 0
			z = 0
	elif y > c:
		y -= c
		if b >= y:
			y -= b
			y = 0
		else:
			a -= y - b
			b = 0
			y = 0
	if z > a:
		k -= 2 * (z - a)
	print(k)


for _ in range(int(input())):
	[zero_1, one_1, two_1] = list(map(int, input().split()))
	[zero_2, one_2, two_2] = list(map(int, input().split()))
	num_2_1 = min(two_1, one_2)
	two_1 = two_1 - num_2_1
	one_2 = one_2 - num_2_1
	num_2_2 = min(two_1, two_2)
	two_1 -= num_2_2
	two_2 -= num_2_2
	num_2_0 = min(two_1, zero_2)
	two_1 -= num_2_0
	zero_2 -= two_1
	num_0_2 = min(zero_1, two_2)
	zero_1 -= num_0_2
	two_2 -= num_0_2
	num_0_0 = min(zero_1, zero_2)
	zero_1 -= num_0_0
	zero_2 -= num_0_0
	num_0_1 = min(zero_1, one_2)
	zero_1 -= num_0_1
	one_2 -= num_0_1
	num_1_0 = min(one_1, zero_2)
	one_1 -= num_1_0
	zero_2 -= num_1_0
	num_1_1 = min(one_1, one_2)
	one_1 -= num_1_1
	one_2 -= num_1_1
	num_1_2 = min(one_1, two_2)
	one_1 -= num_1_2
	two_2 -= num_1_2
	print(2 * num_2_1 - 2 * num_1_2)


def answer(x1, y1, z1, x2, y2, z2):
	if x1 >= z2:
		return 2 * min(z1, y2)
	else:
		z2 = z2 - x1
		if z2 >= z1:
			z2 = z2 - z1
			return -2 * min(z2, y1)
		else:
			z1 = z1 - z2
			return 2 * min(z1, y2)
t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	print(answer(x1, y1, z1, x2, y2, z2))


from collections import Counter
t = int(input())
while t > 0:
	t -= 1
	d = [int(x) for x in input().split()]
	d1 = [int(x) for x in input().split()]
	s = 0
	if d[2] > 0 and d1[1] > 0:
		k = min(d[2], d1[1])
		s += 2 * k
		d[2] -= k
		d1[1] -= k
	if d[0] > 0 and d1[2] > 0:
		k = min(d[0], d1[2])
		d[0] -= k
		d1[2] -= k
	if d[2] > 0 and d1[2] > 0:
		k = min(d[2], d1[2])
		d[2] -= k
		d1[2] -= k
	if d[1] > 0 and d1[1] > 0:
		k = min(d[1], d1[1])
		d[1] -= k
		d1[1] -= k
	if d[0] > 0 and d1[0] > 0:
		k = min(d[0], d1[0])
		d[0] -= k
		d1[0] -= k
	if d[1] > 0 and d1[0] > 0:
		k = min(d[1], d1[0])
		d[1] -= k
		d1[0] -= k
	if d[1] > 0 and d1[2] > 0:
		k = min(d[1], d1[2])
		s -= k * 2
	print(s)


import io, os

def FastInt(zero=0):
	(_ord, nums, num, neg) = (lambda x: x, [], zero, False)
	(i, s) = (0, io.BytesIO(os.read(0, os.fstat(0).st_size)).read())
	try:
		while True:
			if s[i] >= b'0'[0]:
				num = 10 * num + _ord(s[i]) - 48
			elif s[i] == b'-'[0]:
				neg = True
			elif s[i] != b'\r'[0]:
				nums.append(-num if neg else num)
				(num, neg) = (zero, False)
			i += 1
	except IndexError:
		pass
	if s and s[-1] >= b'0'[0]:
		nums.append(-num if neg else num)
	return nums
inp = FastInt()
ii = 0
_T_ = inp[ii]
ii += 1
for _t_ in range(_T_):
	(a0, a1, a2) = inp[ii:ii + 3]
	ii += 3
	(b0, b1, b2) = inp[ii:ii + 3]
	ii += 3
	su = 0
	temp = min(a2, b1)
	su += 2 * temp
	a2 -= temp
	b1 -= temp
	temp = min(a0, b2)
	a0 -= temp
	b2 -= temp
	temp = min(a0, b0)
	a0 -= temp
	b0 -= temp
	temp = min(a1, b1)
	a1 -= temp
	b1 -= temp
	temp = min(a2, b2)
	a2 -= temp
	b2 -= temp
	temp = min(a1, b2)
	su -= 2 * temp
	a1 -= temp
	b2 -= temp
	temp = min(a0, b1)
	a0 -= temp
	b1 -= temp
	print(su)


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	d = min(c, y)
	e = max(0, z - (c - d + a))
	r = 2 * (d - e)
	print(r)


for _ in range(int(input())):
	(x, y, z) = list(map(int, input().split()))
	(a, b, c) = list(map(int, input().split()))
	val = 2 * min(z, b)
	minn = min(z, b)
	z -= minn
	b -= minn
	if c <= x + z:
		print(val)
	else:
		val -= 2 * min(y, c - (x + z))
		print(val)


list_ans = []
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if z2 <= x1:
		list_ans.append(2 * min(y2, z1))
	elif z2 <= x1 + z1:
		list_ans.append(2 * min(y2, z1 + x1 - z2))
	else:
		list_ans.append(-2 * (z2 - x1 - z1))
for item in list_ans:
	print(item)


def ans(A, B):
	ret = 0
	pos_match = min(A[2], B[1])
	A[2] -= pos_match
	B[1] -= pos_match
	ret += 2 * pos_match
	assert sum(A) == sum(B)
	N = sum(A)
	x = B[2]
	y = A[1]
	neg_match = x + y - N
	if neg_match > 0:
		ret -= 2 * neg_match
	return ret
T = int(input())
for t in range(T):
	A = input().split()
	A = list(map(int, A))
	B = input().split()
	B = list(map(int, B))
	print(ans(A, B))


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input().strip('\n')
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
lsc = lambda : list(input().strip('\n').split(' '))
lsi = lambda : [int(i) for i in ls()]
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	(z1, o1, t1) = f()
	(z2, o2, t2) = f()
	ans = 2 * min(t1, o2)
	if t1 > o2:
		t1 -= o2
		o2 = 0
	else:
		o2 -= t1
		t1 = 0
	if t1 > 0:
		x = min(t1, t2)
		t1 -= x
		t2 -= x
		x = min(z1, t2)
		z1 -= x
		t2 -= x
		x = min(o1, z2)
		o1 -= x
		z2 -= x
		print(ans - t2 * 2)
	elif o2 >= 0:
		x = min(z1, t2)
		z1 -= x
		t2 -= x
		print(ans - 2 * t2)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = map(int, input().split())
	ans = 0
	if c1 <= a:
		ans = min(c, b1) * 2
	else:
		c1 = c1 - a
		if c >= c1:
			c = c - c1
			ans = min(c, b1) * 2
		else:
			ans = -1 * (c1 - c) * 2
	print(ans)


n = int(input())
A = []
for i in range(n):
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	s = 0
	if x[0] > y[2]:
		x[0] = x[0] - y[2]
		y[2] = 0
	else:
		y[2] = y[2] - x[0]
		x[0] = 0
	if y[2] == 0:
		s += 2 * min(x[2], y[1])
	elif x[0] == 0:
		if x[2] > y[2]:
			x[2] = x[2] - y[2]
			y[2] = 0
		else:
			y[2] = y[2] - x[2]
			x[2] = 0
		if x[2] == 0:
			s = s - 2 * min(x[1], y[2])
		elif y[2] == 0:
			s += 2 * min(x[2], y[1])
	A.append(s)
for i in A:
	print(i)


def sol():
	(z1, o1, t1) = map(int, input().split())
	(z2, o2, t2) = map(int, input().split())
	sumy = 0
	sumy += min(t1, o2) * 2
	yy = min(t1, o2)
	t1 -= yy
	o2 -= yy
	if True:
		ony = min(o1, z2 + o2)
		o1 -= ony
		sumy -= min(o1, max(t2 - t1, 0)) * 2
		return sumy
for _ in range(int(input())):
	print(sol())


def ternary_seq(x1, x2):
	(zero1, one1, two1) = x1
	(zero2, one2, two2) = x2
	total = 0
	if two1 > 0:
		if two1 >= one2:
			total += one2 * 2
			two1 = two1 - one2
			one2 = 0
		else:
			total += two1 * 2
			one2 = one2 - two1
			two1 = 0
		if two1 > 0:
			if two1 >= two2:
				two1 = two1 - two2
				two2 = 0
			else:
				two2 = two2 - two1
				two1 = 0
		if two1 > 0:
			two1 = 0
			zero2 -= two1
	if one1 > 0:
		if one1 >= one2:
			one1 = one1 - one2
			one2 = 0
		else:
			one2 = one2 - one1
			one1 = 0
		if one1 > 0:
			if one1 >= zero2:
				one1 = one1 - zero2
				zero2 = 0
			else:
				zero2 = zero2 - one1
				one1 = 0
		if one1 > 0:
			total -= one1 * 2
			one1 = 0
			two2 -= one1
	return total
t = int(input())
for x in range(t):
	x1 = list(map(int, input().split()))
	x2 = list(map(int, input().split()))
	print(ternary_seq(x1, x2))


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	abc = stdin.readline().split()
	a = int(abc[0])
	b = int(abc[1])
	c = int(abc[2])
	xyz = stdin.readline().split()
	x = int(xyz[0])
	y = int(xyz[1])
	z = int(xyz[2])
	if z >= a:
		z -= a
		a = 0
	else:
		a -= z
		z = 0
	if z <= c:
		c -= z
		z = 0
		stdout.write(str(2 * min(y, c)) + '\n')
	else:
		stdout.write(str(-2 * (z - c)) + '\n')


for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	max_sum = 2 * min(b1, a2)
	a2 -= min(b1, a2)
	if b2 > a0 + a2:
		max_sum -= (b2 - a0 - a2) * 2
	print(max_sum)


import collections

def sort(key):
	return len(key[1])

def solve(lst1, lst2):
	if not lst2[1] and (not lst2[2]):
		return 0
	if lst1[0] >= lst2[2]:
		lst1[0] = lst1[0] - lst2[2]
		lst2[2] = 0
	elif lst1[0] < lst2[2]:
		lst2[2] = lst2[2] - lst1[0]
		lst1[0] = 0
	if lst2[2] and lst2[2] < lst1[2]:
		lst1[2] = lst1[2] - lst2[2]
		lst2[2] = 0
	elif lst2[2] and lst2[2] >= lst1[2]:
		lst2[2] = lst2[2] - lst1[2]
		lst1[2] = 0
	if lst1[2] and lst1[2] >= lst2[1]:
		lst1[2] = lst2[1]
		lst2[1] = 0
	sumed = -lst2[2] * 2 + lst1[2] * 2
	return sumed
ans = []
n = int(input())
for i in range(n):
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	print(solve(lst1, lst2))
for i in ans:
	print(i)


import sys

def main():
	t = Iint()
	for _ in range(t):
		(a0, a1, a2) = Imap()
		(b0, b1, b2) = Imap()
		t = min(a2, b1)
		ans = t * 2
		a2 -= t
		b1 -= t
		a0 += a2
		b0 += b1
		t = min(a0, b2)
		a0 -= t
		b2 -= t
		ans -= 2 * b2
		print(ans)
FIO = 10

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
en = enumerate

def answer_debug(*args):
	print('\x1b[31m', *args, '\x1b[0m', file=sys.stderr)

def debug(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_greater_b = min(a[2], b[1])
	result = 2 * a_greater_b
	(a[2], b[1]) = (a[2] - a_greater_b, b[1] - a_greater_b)
	if a[0] + a[2] < b[2]:
		amp = b[2] - a[0] - a[2]
		print(result - 2 * min(amp, a[1]))
	elif b[0] + b[1] < a[1]:
		bmp = a[1] - b[0] - b[2]
		print(result - 2 * min(bmp, b[2]))
	else:
		print(result)


def compute_max_c_sum(a_seq_params, b_seq_params):
	(a_zeros, a_ones, a_twos) = a_seq_params
	(b_zeros, b_ones, b_twos) = b_seq_params
	result = 0
	b_twos_with_a_zeros = min(b_twos, a_zeros)
	result += 0 * b_twos_with_a_zeros
	b_twos -= b_twos_with_a_zeros
	a_zeros -= b_twos_with_a_zeros
	if a_zeros == 0:
		a_twos_with_b_twos = min(a_twos, b_twos)
		result += 0 * a_twos_with_b_twos
		a_twos -= a_twos_with_b_twos
		b_twos -= a_twos_with_b_twos
		if a_twos == 0:
			a_ones_with_b_twos = min(a_ones, b_twos)
			result += -2 * a_ones_with_b_twos
			a_ones -= a_ones_with_b_twos
			b_twos -= a_ones_with_b_twos
	a_twos_with_b_ones = min(a_twos, b_ones)
	result += 2 * a_twos_with_b_ones
	a_twos -= a_twos_with_b_ones
	b_ones -= a_twos_with_b_ones
	return result

def main():
	t = int(input())
	for i in range(t):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		result = compute_max_c_sum((x1, y1, z1), (x2, y2, z2))
		print(result)
main()


l = []
for _ in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	c = 0
	if z1 >= y2:
		c = c + 2 * y2
		z1 = z1 - y2
		y2 = 0
		if x1 + z1 >= z2:
			l.append(c)
		else:
			l.append(c - 2 * min(z2 - z1 - x1, y1))
	else:
		c = c + 2 * z1
		z1 = 0
		y2 = y2 - z1
		if z2 <= x1:
			l.append(c)
		else:
			l.append(c - 2 * min(z2 - x1, y1))
for i in l:
	print(i)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def dfs(graph, start=0):
	n = len(graph)
	dp = [0] * n
	(visited, finished) = ([False] * n, [False] * n)
	stack = [start]
	while stack:
		start = stack[-1]
		if not visited[start]:
			visited[start] = True
			for child in graph[start]:
				if not visited[child]:
					stack.append(child)
		else:
			stack.pop()
			dp[start] += 1
			for child in graph[start]:
				if finished[child]:
					dp[start] += dp[child]
			finished[start] = True
	return (visited, dp)
from collections import deque
for _ in range(int(input()) if True else 1):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	ans = 0
	k = min(x2, y1)
	ans += 2 * k
	x2 -= k
	y1 -= k
	k = min(x0, y2)
	x0 -= k
	y2 -= k
	k = min(x2, y2)
	x2 -= k
	y2 -= k
	k = min(y0, x1)
	y0 -= k
	x1 -= k
	k = min(x1, y1)
	x1 -= k
	y1 -= k
	ans -= 2 * min(x1, y2)
	print(ans)


t = int(input())
for _ in range(t):
	(a0, a1, a2) = list(map(int, input().split()))
	(b0, b1, b2) = list(map(int, input().split()))
	print(2 * (min(a2, b1) - min(a1 - min(b0, a1), b2 - min(a0, b2))))


def ntr(num):
	if num <= 0:
		return 0
	return num

def solution(a, b):
	res = 0
	stuff = min(a[2], b[1])
	a[2] -= stuff
	b[1] -= stuff
	res += stuff * 2
	stuff = min(a[0], b[2])
	a[0] -= stuff
	b[2] -= stuff
	stuff = min(a[2], b[2])
	a[2] -= stuff
	b[2] -= stuff
	stuff = min(a[1], b[2])
	res -= stuff * 2
	return res

def main():
	for test in range(int(input())):
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print(solution(a, b))
main()


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()


def answer(a0, a1, a2, b0, b1, b2):
	sum = 0
	if a2 > b1:
		sum = 2 * b1
		a2 -= b1
		if a2 > b2:
			return sum
		else:
			b2 -= a2
			if b2 > a0:
				b2 -= a0
				return sum - 2 * min(b2, a1)
			else:
				return sum
	else:
		sum = 2 * a2
		b1 -= a2
		if b1 > a1:
			return sum
		else:
			a1 -= b1
			if a1 < b0:
				return sum
			else:
				a1 -= b0
				return sum - 2 * min(a1, b2)
for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	print(answer(a0, a1, a2, b0, b1, b2))


for t in range(int(input())):
	l1 = [int(i) for i in input().split()]
	l2 = [int(i) for i in input().split()]
	val = 0
	num = min(l1[0], l2[2])
	l1[0] -= num
	l2[2] -= num
	num = min(l1[0], l2[0])
	l1[0] -= num
	l2[0] -= num
	num = min(l1[0], l2[1])
	l1[0] -= num
	l2[1] -= num
	for i in range(2, 0, -1):
		if i == 2:
			num = min(l1[2], l2[1])
			val += 2 * num
			l1[2] -= num
			l2[1] -= num
			if l1[2] == 0:
				continue
			num = min(l1[2], l2[2])
			l1[2] -= num
			l2[2] -= num
			if l1[2] == 0:
				continue
			l2[0] -= l1[2]
			l1[2] = 0
		elif i == 1:
			num = min(l1[1], l2[1])
			l1[1] -= num
			l2[1] -= num
			if l1[1] == 0:
				continue
			num = min(l1[1], l2[0])
			l1[1] -= num
			l2[0] -= num
			if l1[1] == 0:
				continue
			num = min(l1[1], l2[2])
			val -= 2 * num
			l1[1] -= num
			l2[2] -= num
	print(val)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	pos = min(z1, y2)
	sum = pos * 2
	neg = 0
	if z1 == pos:
		if x1 < z2:
			neg = min(z2 - x1, y1)
			sum -= neg * 2
	elif y2 == pos:
		z1 -= pos
		if x1 + z1 < z2:
			neg = min(y1, z2 - (x1 + z1))
			sum -= neg * 2
	print(sum)


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	arra = []
	for i in temparr:
		arra.append(int(i))
	temparr = input()
	temparr = temparr.split()
	arrb = []
	for i in temparr:
		arrb.append(int(i))
	a0 = arra[0]
	a1 = arra[1]
	a2 = arra[2]
	b0 = arrb[0]
	b1 = arrb[1]
	b2 = arrb[2]
	ans = 0
	getrid = min(b2, a0)
	b2 -= getrid
	a0 -= getrid
	getrid = min(b2, a2)
	a2 -= getrid
	b2 -= getrid
	maxans = min(a2, b1)
	ans += maxans * 2
	a2 -= maxans
	b1 -= maxans
	getrid = min(b1, a0)
	b1 -= getrid
	a0 -= getrid
	if b2 > 0:
		ans -= b2 * 2
	print(ans)


t = int(input())
for j in range(t):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	if z2 > x1:
		count_2 = z2 - x1
		if y2 < z1:
			sum_1 = y2 * 2
			if count_2 > z1 - y2:
				sum_1 -= 2 * (count_2 - (z1 - y2))
				print(sum_1)
			else:
				print(sum_1)
		else:
			sum_1 = z1 * 2
			sum_1 -= count_2 * 2
			print(sum_1)
	elif z1 <= y2:
		print(z1 * 2)
	else:
		print(y2 * 2)


def f():
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	sum = min(a2, b1) * 2
	(b2, a0) = (b2 - min(b2, a0), a0 - min(a2, a0))
	(b1, a2) = (b1 - min(a2, b1), a2 - min(a2, b1))
	(a2, b2) = (a2 - min(a2, b2), b2 - min(a2, b2))
	(a1, b1) = (a1 - min(a1, b1), b1 - min(a1, b1))
	(a1, b0) = (a1 - min(a1, b0), b0 - min(a1, b0))
	sum -= min(b2, a1) * 2
	print(sum)
for _ in range(int(input())):
	f()


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(xa, ya, za) = map(int, sys.stdin.readline().split(' '))
	(xb, yb, zb) = map(int, sys.stdin.readline().split(' '))
	d = min(xa, zb)
	xa -= d
	zb -= d
	ans = 0
	if zb == 0:
		ans = 2 * min(za, yb)
	else:
		d = min(ya, xb)
		ya -= d
		xb -= d
		if ya == 0:
			ans = 2 * min(za, yb)
		else:
			d = min(ya, yb)
			ya -= d
			yb -= d
			if ya == 0:
				ans = 2 * min(za, yb)
			else:
				ans -= 2 * min(ya, zb)
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


size = int(input())
for i in range(size):
	ans = 0
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	step1 = min(arr1[2], arr2[1])
	arr1[2] -= step1
	arr2[1] -= step1
	ans = ans + step1 * 2
	step3 = min(arr1[2], arr2[0])
	arr1[1] -= step3
	arr2[0] -= step3
	step2 = min(arr1[1], arr2[0])
	arr1[1] -= step2
	arr2[0] -= step2
	ans = ans + 0
	step5 = min(arr1[1], arr2[1])
	arr1[1] -= step5
	arr2[1] -= step5
	step5 = min(arr1[0], arr2[0])
	arr1[0] -= step5
	arr2[0] -= step5
	step5 = min(arr1[0], arr2[1])
	arr1[0] -= step5
	arr2[1] -= step5
	step5 = min(arr1[0], arr2[2])
	arr1[0] -= step5
	arr2[2] -= step5
	step8 = min(arr1[2], arr2[2])
	arr1[2] -= step8
	arr2[2] -= step8
	step4 = min(arr1[1], arr2[2])
	ans = ans - step4 * 2
	print(ans)


for _ in range(int(input())):
	c = 0
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	plus = min(z1, y2)
	z1 -= plus
	y2 -= plus
	c += plus * 2
	minus = min(y1, z2 - x1 - z1)
	if minus > 0:
		c -= minus * 2
	print(c)


import sys
import itertools
import collections
for _ in range(int(input().strip())):
	(x1, y1, z1) = map(int, input().strip().split())
	(x2, y2, z2) = map(int, input().strip().split())
	mx_0_can_make = min(x1, z2)
	x1 -= mx_0_can_make
	z2 -= mx_0_can_make
	mx_0_can_make = min(y1, x2)
	y1 -= mx_0_can_make
	x2 -= mx_0_can_make
	mx_2_can_make = min(z1, y2)
	z1 -= mx_2_can_make
	y2 -= mx_2_can_make
	ans = mx_2_can_make * 2 - 2 * min(y1, z2)
	print(ans)


for t in range(int(input())):
	(z1, o1, t1) = map(int, input().split())
	(z2, o2, t2) = map(int, input().split())
	count = 0
	if t1 > o2:
		count += o2 * 2
		t1 -= o2
		if t2 > t1:
			t2 -= t1
			if t2 > z1:
				t2 -= z1
				if o1 > z2:
					o1 -= z2
					count -= min(t2, o1) * 2
	elif t1 < o2:
		count += t1 * 2
		o2 -= t1
		if o1 > o2:
			o1 -= o2
			if o1 > z2:
				o1 -= z2
				if t2 > z1:
					t2 -= z1
					count -= min(t2, o1) * 2
	elif t1 == o2:
		count += o2 * 2
		if z2 < o1:
			o1 -= z2
			if t2 > z1:
				t2 -= z1
				count -= min(t2, o1) * 2
	print(count)


import math
for q in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans1 = []
	ans2 = []
	c = 0
	s = min(z1, y2)
	if y2 > z1:
		c = y2 - z1
	if y1 < c + x2:
		print(2 * s)
	else:
		print(2 * (s - (y1 - (c + x2))))


n = int(input())
while n:
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	sum = 2 * min(c, y)
	c -= min(c, y)
	y -= min(c, y)
	z -= c
	z -= a
	sum -= 2 * max(0, z)
	print(sum)
	n -= 1


def solve(num1s, num2s):
	a2 = num1s[2]
	b1 = num2s[1]
	v1 = min(a2, b1)
	ans = v1 * 2
	a2 -= v1
	b1 -= v1
	a0 = num1s[0]
	b2 = num2s[2]
	v2 = min(a0 + a2, b2)
	b2 -= v2
	a1 = num1s[1]
	if b2 > 0 and a1 > 0:
		ans -= 2 * min(a1, b2)
	return ans
for _ in range(int(input())):
	num1s = list(map(int, input().split()))
	num2s = list(map(int, input().split()))
	print(solve(num1s, num2s))


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
from math import *
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	temp = min(a[-1], b[1])
	ans += 2 * temp
	a[-1] -= temp
	b[1] -= temp
	temp = min(a[-1], b[-1])
	a[-1] -= temp
	b[-1] -= temp
	temp = min(a[-1], b[0])
	a[-1] -= temp
	b[0] -= temp
	temp = min(a[1], b[1])
	a[1] -= temp
	b[1] -= temp
	temp = min(a[1], b[0])
	a[1] -= temp
	b[0] -= temp
	temp = min(a[0], b[-1])
	a[0] -= temp
	b[-1] -= temp
	temp = min(a[0], b[1])
	a[0] -= temp
	b[1] -= temp
	temp = min(a[0], b[0])
	a[0] -= temp
	b[0] -= temp
	temp = min(a[1], b[-1])
	a[1] -= temp
	b[-1] -= temp
	ans -= 2 * temp
	print(ans)


t = int(input())
for i in range(t):
	(c1, b1, a1) = map(int, input().split())
	(c2, b2, a2) = map(int, input().split())
	ans = 0
	x1 = min(c1, a2)
	c1 -= x1
	a2 -= x1
	x2 = min(a1, b2)
	ans += x2 * 2
	b2 -= x2
	a1 -= x2
	x3 = min(a1, a2)
	a2 -= x3
	a1 -= x3
	x4 = min(b1, a2)
	ans -= x4 * 2
	print(ans)


def sso(x, y):
	z = min(x[0], y[0])
	x[0] -= z
	y[0] -= z
	return z
T = int(input())
for t in range(T):
	(x1, y1, z1) = [int(j) for j in input().split()]
	(x2, y2, z2) = [int(j) for j in input().split()]
	(zeros1, ones1, twos1) = ([x1], [y1], [z1])
	(zeros2, ones2, twos2) = ([x2], [y2], [z2])
	total = 0
	total += 2 * sso(twos1, ones2)
	sso(twos1, twos2)
	sso(twos1, zeros2)
	sso(ones1, ones2)
	sso(ones1, zeros2)
	sso(zeros1, twos2)
	sso(zeros1, ones2)
	sso(zeros1, zeros2)
	total -= 2 * sso(ones1, twos2)
	print(total)


def test():
	t = int(input())
	while t > 0:
		t -= 1
		soln()

def soln():
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	m = min(a[2], b[1])
	s = 2 * m
	a[2] -= m
	b[1] -= m
	a[1] = a[1] - b[0] - b[1]
	b[2] = b[2] - a[0] - a[2]
	if a[1] > 0 and b[2] > 0:
		s = s - 2 * min(a[1], b[2])
	print(s)
test()


for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = min(a[2], b[1])
	total = mini * 2
	a[2] -= mini
	b[1] -= mini
	maxi = max(0, b[2] - a[2] - a[0])
	total -= maxi * 2
	print(total)


def gt():
	return list(map(int, input().split()))
(t,) = gt()
for _ in range(t):
	(a, b, c) = gt()
	(d, e, f) = gt()
	print((min(c, e) - max(0, f - c + min(c, e) - a)) * 2)


t = int(input())
for i in range(t):
	(x0, x1, x2) = input().split()
	(x0, x1, x2) = (int(x0), int(x1), int(x2))
	(y0, y1, y2) = input().split()
	(y0, y1, y2) = (int(y0), int(y1), int(y2))
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x0, y2)
	x0 -= m
	y2 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	sum = 0
	sum += 2 * m
	sum -= 2 * min(x1, y2)
	print(sum)


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


t = int(input())
while t:
	t -= 1
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	ans += 2 * min(a[2], b[1])
	k = min(a[2], b[1])
	b[1] = max(b[1] - k, 0)
	a[2] = max(a[2] - k, 0)
	if b[0] + b[1] >= a[1]:
		print(ans)
	else:
		ans -= 2 * min(a[1] - b[0] - b[1], b[2])
		print(ans)


def solution(a: list, b: list):
	val = 0
	count = min(a[2], b[1])
	val += count * 2
	a[2] -= count
	b[1] -= count
	if a[2]:
		count = min(a[2], b[2])
		a[2] -= count
		b[2] -= count
		if a[2]:
			return val
	if b[2]:
		count = min(a[0], b[2])
		a[2] -= count
		b[2] -= count
		if b[2]:
			val -= 2 * b[2]
			return val
	return val
test_case = int(input())
for _ in range(test_case):
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print(solution(a, b))


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prdbg(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
	pass

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	ac = list(rint())
	bc = list(rint())
	n = sum(ac)
	ans = 0
	if ac[2] < bc[1]:
		ans += ac[2] * 2
		rem = n - ac[2]
		if ac[1] < bc[2]:
			if ac[1] <= rem - bc[2]:
				pass
			else:
				ans -= 2 * (ac[1] - (rem - bc[2]))
		elif bc[2] <= rem - ac[1]:
			pass
		else:
			ans -= 2 * (bc[2] - (rem - ac[1]))
	else:
		ans += bc[1] * 2
		rem = n - bc[1]
		if ac[1] < bc[2]:
			if ac[1] <= rem - bc[2]:
				pass
			else:
				ans -= 2 * (ac[1] - (rem - bc[2]))
		elif bc[2] <= rem - ac[1]:
			pass
		else:
			ans -= 2 * (bc[2] - (rem - ac[1]))
	print(ans)


def main():
	t = int(input())
	for case in range(t):
		(x, y, z) = [int(x) for x in input().split()]
		(a, b, c) = [int(x) for x in input().split()]
		sumC = 0
		min_2 = min(z, b)
		sumC += min_2 * 2
		if z <= b:
			b -= z
			z = 0
			if y <= b + a:
				print(sumC)
			else:
				min_1 = min(y - b - a, c - x)
				if min_1 > 0:
					sumC -= min_1 * 2
				print(sumC)
		else:
			z -= b
			b = 0
			if c <= z + x:
				print(sumC)
			else:
				min_2b = min(c - z - x, y - a)
				if min_2b > 0:
					sumC -= min_2b * 2
				print(sumC)
	return
main()


for _ in range(int(input())):
	one = list(map(int, input().split()))
	two = list(map(int, input().split()))
	ans = 0
	if one[2] > 0:
		d = min(one[2], two[1])
		one[2] -= d
		two[1] -= d
		ans += d * 2
	for i in range(2, -1, -2):
		if one[2] > 0:
			d = min(one[2], two[i])
			one[2] -= d
			two[i] -= d
		else:
			break
	for i in range(3):
		if one[1] > 0:
			d = min(one[1], two[i])
			one[1] -= d
			two[i] -= d
			if i == 2:
				ans -= d * 2
		else:
			break
	print(ans)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	mx = 0
	ma2 = min(z1, y2)
	mx += ma2 * 2
	z1 -= ma2
	y2 -= ma2
	mb2 = min(z1, z2)
	z1 -= mb2
	z2 -= mb2
	mb2 = min(x1, z2)
	z2 -= mb2
	x1 -= mb2
	ma1 = min(y1, z2)
	z2 -= ma1
	y1 -= ma1
	mx -= ma1 * 2
	stdout.write(str(mx) + '\n')


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	res = min(z1, y2) * 2
	mn = min(z1, y2)
	z1 -= mn
	y2 -= mn
	if y2 > z1:
		if x1 >= z2:
			print(res)
			continue
		z2 -= x1
		res -= 2 * z2
		print(res)
		continue
	elif z1 + x1 >= z2:
		print(res)
		continue
	else:
		z2 -= z1 + x1
		res -= 2 * z2
		print(res)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(Iint()):
		(x0, x1, x2) = Ilist()
		(y0, y1, y2) = Ilist()
		m = min(x0, y2)
		x0 -= m
		y2 -= m
		m = min(x1, y0)
		x1 -= m
		y0 -= m
		m = min(x2, y1)
		x2 -= 1
		y1 -= 1
		sum_output = 2 * m
		sum_output -= 2 * min(x1, y2)
		print(sum_output)

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(x1, y1, z1) = tuple(map(int, input().split()))
	(x2, y2, z2) = tuple(map(int, input().split()))
	final = 0
	if z1 <= y2:
		final += 2 * z1
		y2 = y2 - z1
		z1 = 0
	else:
		final += 2 * y2
		z1 = z1 - y2
		y2 = 0
	if x1 + z1 < z2:
		final -= 2 * (z2 - (x1 + z1))
	print(final)


from sys import stdin, stdout
from collections import Counter, OrderedDict
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
(t,) = mp()
for _ in range(t):
	l1 = mp()
	l2 = mp()
	ans = 0
	z = min(l1[2], l2[1])
	ans += 2 * z
	l1[2] -= z
	l2[1] -= z
	z = min(l1[2], l2[2])
	l1[2] -= z
	l2[2] -= z
	z = min(l1[2], l2[0])
	l1[2] -= z
	l2[0] -= z
	z = min(l1[1], l2[1])
	l1[1] -= z
	l2[1] -= z
	z = min(l1[1], l2[0])
	l1[1] -= z
	l2[0] -= z
	z = min(l1[1], l2[2])
	ans -= 2 * z
	l1[1] -= z
	l2[2] -= z
	cout(str(ans) + '\n')


t = int(input())
for i in range(t):
	a = []
	(x, y, z) = map(int, input().split())
	a0 = x
	a1 = y
	a2 = z
	(x, y, z) = map(int, input().split())
	b0 = x
	b1 = y
	b2 = z
	sumo = 0
	res = 0
	if a2 > 0 and b1 > 0:
		if a2 > b1:
			sumo = sumo + b1 * 2
			res = a2 - b1
		else:
			sumo = sumo + a2 * 2
	if a2 > b1:
		res = a2 - b1
	if a0 + res >= b2:
		pass
	else:
		lok = (b2 - (a0 + res)) * 2
		sumo = sumo - lok
	print(sumo)


def main():
	t = int(input())
	ans = []
	for i in range(t):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		total = 0
		total += 2 * min(z1, y2)
		x = min(z1, y2)
		z1 -= x
		y2 -= x
		a = [x1, y1, z1]
		b = [x2, y2, z2]
		for j in range(2, -1, -1):
			for k in range(j, -1, -1):
				x = min(a[j], b[k])
				a[j] -= x
				b[k] -= x
		for j in range(3):
			x = min(a[0], b[j])
			a[0] -= x
			b[j] -= x
		total -= 2 * min(a[1], b[2])
		ans.append(str(total))
	print('\n'.join(ans))
main()


t = int(input())
for i in range(0, t):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	cost = 0
	m = min(b1, a2)
	b1 -= m
	a2 -= m
	m = min(a1, c2)
	a1 -= m
	c2 -= m
	m = min(c1, b2)
	c1 -= m
	b2 -= m
	cost += 2 * m
	x = min(b1, c2)
	cost -= 2 * x
	print(cost)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	res = 0
	x = min(c, e)
	(c, e) = (c - x, e - x)
	res += 2 * x
	(a, f) = (a - min(a, f), f - min(a, f))
	(b, e) = (b - min(b, e), e - min(b, e))
	(c, f) = (c - min(c, f), f - min(c, f))
	res += -2 * min(b, f)
	print(res)


t = int(input())
while t > 0:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = 0
	tem = min(z1, y2)
	c += 2 * tem
	z1 -= tem
	y2 -= tem
	if z1 > 0:
		tem = min(z1, z2)
		z1 -= tem
		z2 -= tem
	if z2 > 0:
		tem = min(z2, x1)
		x1 -= tem
		z2 -= tem
	if z2 > 0:
		tem = min(z2, y1)
		c -= 2 * tem
		y1 - tem
		z2 -= tem
	print(c)
	t -= 1


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	total = 0
	if z1 > 0:
		if z1 > 0 and y2 > 0:
			mi = min(z1, y2)
			total += mi * 2
			z1 -= mi
			y2 -= mi
		if z2 > 0 and z1 > 0:
			mi = min(z1, z2)
			z2 -= mi
			z1 -= mi
		if z1 > 0 and x2 > 0:
			mi = min(z1, x2)
			z1 -= mi
			x2 -= mi
	if x1 > 0:
		if x1 > 0 and z2 > 0:
			mi = min(x1, z2)
			x1 -= mi
			z2 -= mi
		if x1 > 0 and y2 > 0:
			mi = min(x1, y2)
			x1 -= mi
			y2 -= mi
		if x1 > 0 and x2 > 0:
			mi = min(x1, x2)
			x1 -= mi
			x2 -= mi
	if y1 > 0:
		if y1 > 0 and x2 > 0:
			mi = min(y1, x2)
			y1 -= mi
			x2 -= mi
		if y1 > 0 and y2 > 0:
			mi = min(y1, y2)
			y2 -= mi
			y1 -= mi
		if y1 > 0 and z2 > 0:
			mi = min(y1, z2)
			total -= mi * 2
			y1 -= mi
			z2 -= mi
	print(total)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	f = 0
	while z1:
		if y2 != 0:
			m = min(z1, y2)
			ans += m * 2
			z1 -= m
			y2 -= m
		elif z2 != 0:
			m = min(z1, z2)
			z1 -= m
			z2 -= m
		else:
			f = 1
			break
	if f == 0:
		while y1:
			if y2 != 0:
				m = min(y1, y2)
				y1 -= m
				y2 -= m
			elif x2 != 0:
				m = min(y1, x2)
				y1 -= m
				x2 -= m
			else:
				ans -= 2 * y1
				break
	print(ans)


T = int(input())
results = []
for ttt in range(T):
	res = 0
	a = [int(item) for item in input().split()]
	b = [int(item) for item in input().split()]
	x = min(a[2], b[1])
	res += x * 2
	a[2] -= x
	b[1] -= x
	y = b[2] - a[2] - a[0]
	if y > 0:
		res -= y * 2
	print(res)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	res = 2 * min(c, y)
	if c >= y:
		c -= y
		if z >= c + a:
			res -= 2 * (z - c - a)
	elif z > a:
		res -= 2 * (z - a)
	print(res)


j = int(input())
for i in range(j):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a[2], b[1])
	w = a[2] - x
	z = max(0, w)
	ans = x * 2
	if z + a[0] >= b[2]:
		print(ans)
	else:
		s = (b[2] - (a[0] + z)) * 2
		print(ans - s)


t = int(input())
ans = []
for case in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	positive = min(a[2], b[1])
	a[2] -= positive
	b[1] -= positive
	zeroandtwo = min(a[0], b[2])
	a[0] -= zeroandtwo
	b[2] -= zeroandtwo
	unaccounted = max(0, b[2] - a[2])
	left = positive - unaccounted
	total = left * 2
	ans.append(total)
for num in ans:
	print(num)


def tInput():
	from sys import stdin
	input = stdin.readline
tInput()

def A():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if n >= k:
			print(int(n % 2 != k % 2))
		else:
			print(k - n)

def B():
	for _ in range(int(input())):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		tot = 0
		p = min(x1, z2)
		x1 -= p
		z2 -= p
		tot += 2 * min(z1, y2)
		p = min(z1, y2)
		z1 -= p
		y2 -= p
		if z2 > 0:
			z2 -= min(z2, z1)
			tot -= 2 * min(y1, z2)
		print(tot)
B()


import sys
input = sys.stdin.buffer.readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
_T_ = inin()
for _t_ in range(_T_):
	(a0, a1, a2) = inar()
	(b0, b1, b2) = inar()
	su = 0
	temp = min(a2, b1)
	su += 2 * temp
	a2 -= temp
	b1 -= temp
	temp = min(a0, b2)
	a0 -= temp
	b2 -= temp
	temp = min(a0, b0)
	a0 -= temp
	b0 -= temp
	temp = min(a1, b1)
	a1 -= temp
	b1 -= temp
	temp = min(a2, b2)
	a2 -= temp
	b2 -= temp
	temp = min(a1, b2)
	su -= 2 * temp
	a1 -= temp
	b2 -= temp
	temp = min(a0, b1)
	a0 -= temp
	b1 -= temp
	print(su)


for t in range(int(input())):
	(az, ao, at) = [int(k) for k in input().split()]
	(tz, to, tt) = [int(k) for k in input().split()]
	ans = 0
	ans += 2 * min(at, to)
	de = min(at, to)
	to -= de
	at -= de
	if tt > 0:
		tt -= min(tt, az + at)
	if ao > 0:
		ao -= min(ao, tz + to)
	ans -= 2 * min(max(0, tt), max(0, ao))
	print(ans)


t = int(input().strip(' '))
for _ in range(t):
	(a0, a1, a2) = map(int, input().strip(' ').split(' '))
	(b0, b1, b2) = map(int, input().strip(' ').split(' '))
	t = 0
	m2 = min((a2, b1))
	t += 2 * m2
	a2 -= m2
	b1 -= m2
	m2 = min((a0, b2))
	b2 -= m2
	a0 -= m2
	if b2 != 0:
		m2 = min((b2, a2))
		b2 -= m2
		a2 -= m2
	if b2 != 0:
		t -= 2 * b2
	print(t)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(a0, a1, a2) = list(map(int, stdin.readline().split()))
	(b0, b1, b2) = list(map(int, stdin.readline().split()))
	used2 = min(a2, b1)
	neg = b2 - (a2 - used2 + a0)
	if neg < 0:
		neg = 0
	print(2 * (used2 - neg))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = map(int, input().split())
	ans = min(c, b1) * 2
	b1 -= min(c, b1)
	b -= min(b, a1)
	b -= min(b, b1)
	ans -= b * 2
	print(ans)


for _ in range(int(input())):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	can = min(c2, a1)
	a1 -= can
	c2 -= can
	if a1 == 0:
		can = min(c1, c2)
		c1 -= can
		c2 -= can
		if c2 == 0:
			can = min(c1, b2)
			ans = 2 * can
		else:
			ans = -2 * c2
	else:
		can = min(c1, b2)
		ans = 2 * can
	print(ans)


from sys import stdout, stdin
(_input, _print) = (stdin.readline, stdout.write)
(_int, _range) = (int, range)

def solution():
	for _ in _range(_int(_input())):
		(a_0, a_1, a_2) = [_int(i) for i in _input().split()]
		(b_0, b_1, b_2) = [_int(i) for i in _input().split()]
		c = 0
		if b_2 > 0:
			if b_2 >= a_0:
				b_2 -= a_0
			else:
				b_2 = 0
			if b_2 >= a_2:
				b_2 -= a_2
				a_2 = 0
			else:
				a_2 -= b_2
				b_2 = 0
			if b_2 > 0:
				c += b_2 * -2
		if a_2 > 0:
			if b_1 < a_2:
				c += b_1 * 2
			else:
				c += a_2 * 2
		print(c)
solution()


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		(x1, y1, z1) = ain()
		(x2, y2, z2) = ain()
		suma = 0
		l = [x2, y2, z2]
		suma = 0
		i = 0
		for i in [1, 2, 0]:
			if z1 > 0 and l[i] > 0:
				x = l[i]
				if i == 1:
					suma += min(x, z1) * 2
				l[i] -= min(x, z1)
				z1 -= min(x, z1)
		for i in [2, 1, 0]:
			if x1 > 0 and l[i] > 0:
				x = l[i]
				l[i] -= min(x, x1)
				x1 -= min(x, x1)
		for i in [0, 1, 2]:
			if y1 > 0 and l[i] > 0:
				x = l[i]
				if i == 2:
					suma -= min(x, y1) * 2
				l[i] -= min(x, y1)
				y1 -= min(x, y1)
		print(suma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t > 0:
	t -= 1
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	main = min(c, q)
	c -= main
	q -= main
	b -= p + q
	print(2 * main - max(min(r, b), 0) * 2)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	if y2 >= z1:
		ans = z1 * 2
		if z2 > x1:
			ans -= (z2 - x1) * 2
	else:
		ans = y2 * 2
		if z2 > x1 + z1 - y2:
			ans -= (z2 - x1 - z1 + y2) * 2
	print(ans)


for w in range(int(input())):
	(x1, y1, z1) = tuple(map(int, input().split()))
	(x2, y2, z2) = tuple(map(int, input().split()))
	t = 0
	t1 = z1
	t2 = y2
	t += 2 * min(z1, y2)
	y2 -= min(t1, t2)
	z1 -= min(t1, t2)
	if z1 > 0:
		t1 = z1
		t2 = z2
		z1 -= min(t1, t2)
		z2 -= min(t1, t2)
	if z1 > 0:
		t1 = z1
		t2 = x2
		z1 -= min(t1, t2)
		x2 -= min(t1, t2)
	if z2 > 0:
		t1 = x1
		t2 = z2
		z2 -= min(t2, t1)
		x1 -= min(t2, t1)
	if z2 > 0:
		t -= 2 * z2
		z2 = 0
	y1 -= min(y1, x2)
	x2 -= min(y1, x2)
	print(t)


t = int(input())
for _ in range(t):
	[x1, y1, z1] = [int(i) for i in input().split()]
	[x2, y2, z2] = [int(i) for i in input().split()]
	if x1 >= z2:
		s = 2 * min(z1, y2)
	elif z1 >= y2:
		if z2 <= x1 + z1 - y2:
			s = 2 * y2
		else:
			s = 2 * (x1 + z1 - z2)
	else:
		s = 2 * (x1 + z1 - z2)
	print(s)


k = int(input())
for _ in range(k):
	(x_a, x_b, x_c) = map(int, input().split())
	(y_a, y_b, y_c) = map(int, input().split())
	y_c -= x_a
	if y_c < 0:
		y_a -= abs(y_c)
		y_c = 0
		if y_a < 0:
			y_b -= abs(y_a)
			y_a = 0
	if y_a:
		x_b -= y_a
		if x_b < 0:
			x_c -= abs(x_b)
			x_b = 0
	if x_c > y_c:
		print(2 * (x_c - y_c))
	elif x_c == y_c:
		print(0)
	else:
		print(-2 * (y_c - x_c))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import Counter, defaultdict, deque

def int1():
	return int(input())

def map1():
	return map(int, input().split())

def list1():
	return list(map(int, input().split()))
mod = pow(10, 9) + 7

def solve():
	(x, y, z) = map1()
	(a, b, c) = map1()
	if x >= c:
		x = x - c
		c = 0
	else:
		c = c - x
		x = 0
	if c != 0:
		if z >= c:
			z = z - c
			c = 0
		else:
			c = c - z
			z = 0
	sum1 = min(b, z) * 2 - min(y, c) * 2
	print(sum1)
for _ in range(int(input())):
	solve()


for i in range(int(input())):
	sum = int(0)
	(x1, y1, z1) = map(int, input().split(' '))
	(x2, y2, z2) = map(int, input().split(' '))
	if z1 >= y2:
		sum += y2 * 2
		z2 -= z1 - y2
	else:
		sum += z1 * 2
		y1 -= y2 - z1
	if y1 == 0:
		print(sum)
	elif x2 >= y1:
		print(sum)
	elif z2 != 0:
		sum += (x2 - y1) * 2
		print(sum)
	else:
		print(sum)


game = int(input())
for i in range(game):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(n10, n11, n12, n20, n21, n22) = (l1[0], l1[1], l1[2], l2[0], l2[1], l2[2])
	if n10 - n22 >= 0:
		k1 = n10 - n22
		k2 = n12 - n21
		if k2 >= 0:
			print(n21 * 2)
		else:
			print(n12 * 2)
	elif n10 + n12 - n22 >= 0:
		k3 = n10 + n12 - n22
		k4 = k3 - n21
		if k4 >= 0:
			print(n21 * 2)
		else:
			print(k3 * 2)
	else:
		k5 = n22 - (n10 + n12)
		print(-(k5 * 2))


for tc in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = min(z1, y2) * 2
	z1 -= ans // 2
	y2 -= ans // 2
	if x1 + z1 > z2:
		print(ans)
	else:
		z2 -= x1
		z2 -= z1
		ans -= z2 * 2
		print(ans)


t = int(input())
for _ in range(t):
	arr1 = [int(p) for p in input().split()]
	arr2 = [int(p) for p in input().split()]
	s = 0
	n2 = arr1[2]
	j = min(n2, arr2[1])
	s += 2 * j
	arr2[1] -= j
	arr1[2] -= j
	n2 -= j
	j = min(n2, arr2[2])
	arr2[2] -= j
	arr1[2] -= j
	n2 -= j
	n0 = arr1[0]
	k = min(n0, arr2[2])
	n0 -= k
	arr2[2] -= k
	arr1[0] -= k
	k = min(n0, arr2[1])
	n0 -= k
	arr2[1] -= k
	arr1[0] -= k
	k = min(n0, arr2[0])
	n0 -= k
	arr2[0] -= k
	arr1[0] -= k
	s -= 2 * min(arr1[1], arr2[2])
	print(s)


def f():
	t = int(input())
	while t != 0:
		t -= 1
		L = [int(i) for i in input().split()]
		(A, K) = (L[0], L[1])
		if K > A:
			print(K - A)
		elif A % 2 == 0 and K % 2 == 0:
			print(0)
		elif A % 2 != 0 and K % 2 != 0:
			print(0)
		else:
			print(1)

def B():
	t = int(input())
	while t != 0:
		t -= 1
		A = [int(i) for i in input().split()]
		B = [int(i) for i in input().split()]
		Ans = 0
		Ans = Ans + 2 * min(A[2], B[1])
		tmp = A[2]
		A[2] = A[2] - min(A[2], B[1])
		B[1] = B[1] - min(tmp, B[1])
		tmp = A[0]
		A[0] = A[0] - min(A[0], B[2])
		B[2] = B[2] - min(tmp, B[2])
		tmp = A[0]
		A[0] = A[0] - min(A[0], B[1])
		B[1] = B[1] - min(tmp, B[1])
		tmp = A[0]
		A[0] = A[0] - min(A[0], B[0])
		B[0] = B[0] - min(tmp, B[0])
		tmp = A[1]
		A[1] = A[1] - min(A[1], B[0])
		B[0] = B[0] - min(tmp, B[0])
		tmp = A[1]
		A[1] = A[1] - min(A[1], B[1])
		B[1] = B[1] - min(tmp, B[1])
		tmp = A[2]
		A[2] = A[2] - min(A[2], B[2])
		B[2] = B[2] - min(tmp, B[2])
		Ans = Ans - 2 * min(A[1], B[2])
		print(Ans)
B()


t = int(input())
while t != 0:
	t = t - 1
	a = [0] * 3
	b = [0] * 3
	a = list(map(int, input().strip().split()))[:3]
	b = list(map(int, input().strip().split()))[:3]
	sum = 0
	sum = sum + 2 * min(a[2], b[1])
	k = min(a[2], b[1])
	a[2] = a[2] - k
	b[1] = b[1] - k
	k = min(a[1], b[1])
	a[1] = a[1] - k
	b[1] = b[1] - k
	k = min(a[0], b[1])
	a[0] = a[0] - k
	b[1] = b[1] - k
	k = min(a[1], b[0])
	a[1] = a[1] - k
	b[0] = b[0] - k
	k = min(a[2], b[2])
	a[2] = a[2] - k
	b[2] = b[2] - k
	k = min(a[2], b[0])
	a[2] = a[2] - k
	b[0] = b[0] - k
	k = min(a[0], b[2])
	a[0] = a[0] - k
	b[2] = b[2] - k
	k = min(a[0], b[0])
	a[0] = a[0] - k
	b[0] = b[0] - k
	k = min(a[1], b[2])
	sum = sum - 2 * k
	print(sum)


n = int(input())
for i in range(n):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	s = 0
	if z1 >= y2 and z1 - y2 + x1 >= z2:
		s += 2 * y2
	elif z1 < y2 and x1 >= z2:
		s += 2 * z1
	elif z1 >= y2 and z1 - y2 + x1 < z2:
		s += 2 * y2 - 2 * (z2 - (z1 - y2 + x1))
	else:
		s += 2 * z1 - 2 * (z2 - x1)
	print(s)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		sm = 0
		(x1, y1, z1) = In()
		(x2, y2, z2) = In()
		x = min(x1, z2)
		x1 -= x
		z2 -= x
		x = min(y1, x2)
		y1 -= x
		x2 -= x
		x = min(z1, y2)
		z1 -= x
		y2 -= x
		sm += 2 * x
		sm -= 2 * min(y1, z2)
		print(sm)
main()


T = int(input())
for _ in range(T):
	(a1, b1, c1) = list(map(int, input().split()))
	(a2, b2, c2) = list(map(int, input().split()))
	ans = 0
	v = b2 - c1
	if v < 0:
		ans = ans + b2 * 2
		c1 = -v
		b2 = 0
		v = c2 - c1
		if v < 0:
			c1 = -v
			c2 = 0
			a2 = a2 + v
		else:
			c2 = v
	else:
		ans = ans + c1 * 2
		b2 = v
	v = a2 + b2 - b1
	if v < 0:
		ans = ans + v * 2
	print(ans)


import math
for i in range(0, int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	min0 = min(x1, z2)
	x1 -= min0
	z2 -= min0
	min0 = min(y1, x2)
	y1 -= min0
	x2 -= min0
	min0 = min(y1, y2)
	y1 -= min0
	y2 -= min0
	min1 = min(z1, y2)
	z1 -= min1
	y2 -= min1
	min0 = min(z1, z2)
	z1 -= min0
	z2 -= min0
	min2 = min(y1, z2)
	print(2 * min1 - 2 * min2)


def checkKey(dict, key):
	if key in dict:
		return True
	return False
test = int(input())
for t_ in range(test):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	s = 0
	temp = min(z1, y2)
	s += 2 * temp
	z1 -= temp
	y2 -= temp
	temp = min(z1, z2)
	s += 0
	z1 -= temp
	z2 -= temp
	temp = min(y1, x2)
	s += 0
	y1 -= temp
	x2 -= temp
	temp = min(y1, y2)
	s += 0
	y1 -= temp
	y2 -= temp
	temp = min(y1, z2)
	s -= 2 * temp
	y1 -= temp
	x2 -= temp
	print(s)


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


mod = 10 ** 9 + 7

def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	x = min(z1, y2)
	ans = 2 * x
	z1 -= x
	y2 -= x
	x = z2 - z1 - x1
	if x > 0:
		ans -= 2 * x
	print(ans)
t = int(input())
while t > 0:
	solve()
	t -= 1


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


for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	if b[2] > a[0] + a[2]:
		b[2] -= a[0] + a[2]
		ans -= b[2] * 2
		a[1] -= b[2]
		b[2] = 0
		a[0] = 0
		a[2] = 0
		print(ans)
	elif b[2] == a[0] + a[2]:
		print(0)
	elif a[2] + a[0] - b[2] < a[2]:
		if a[2] + a[0] - b[2] < b[1]:
			ans += (a[2] + a[0] - b[2]) * 2
			b[1] -= a[2] + a[0] - b[2]
			print(ans)
		else:
			ans += b[1] * 2
			print(ans)
	elif a[2] < b[1]:
		ans += a[2] * 2
		print(ans)
	else:
		ans += b[1] * 2
		print(ans)


def Solve():
	for t in range(int(input())):
		(a0, a1, a2) = map(int, input().split())
		(b0, b1, b2) = map(int, input().split())
		f = 0
		f += min(a2, b1) * 2
		(a2, b1) = (a2 - min(a2, b1), b1 - min(a2, b1))
		while b2 > 0:
			if a2 > 0:
				(b2, a2) = (b2 - min(a2, b2), a2 - min(a2, b2))
			elif a0 > 0:
				(b2, a0) = (b2 - min(a0, b2), a0 - min(a0, b2))
			else:
				f += min(a1, b2) * -2
				(b2, a1) = (b2 - min(a1, b2), a1 - min(a1, b2))
		print(f)
Solve()


def get_ans(a0, a1, a2, b0, b1, b2):
	ans = 0
	if a2 > b1:
		ans += 2 * b1
		a2 -= b1
		b1 = 0
	else:
		ans += 2 * a2
		b1 -= a2
		a2 = 0
	a1 -= b0 + b1
	b2 -= a0 + a2
	if a1 > 0 and b2 > 0:
		ans -= 2 * min(a1, b2)
	return ans
t = int(input())
anss = []
for _ in range(t):
	inp1 = list(map(int, input().split()))
	inp2 = list(map(int, input().split()))
	anss.append(get_ans(inp1[0], inp1[1], inp1[2], inp2[0], inp2[1], inp2[2]))
for i in anss:
	print(i)


from sys import stdin, stdout
import math
print = stdout.write
input = stdin.readline
for p in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	su = 0
	su += 2 * min(z1, y2)
	x = min(z1, y2)
	z1 -= x
	y2 -= x
	x = min(z2, x1)
	x1 -= x
	z2 -= x
	x = min(x1, y2)
	x1 -= x
	y2 -= x
	if x1 == 0:
		if z1 > 0:
			x = min(z1, z2)
			z1 -= x
			z2 -= x
		if z2 > 0:
			su -= 2 * min(y1, z2)
			x = min(y1, z2)
			y1 -= x
			z2 -= x
	print(str(su) + '\n')


def answer(freq1, freq2):
	sum = 0
	score = min(freq1[2], freq2[1])
	freq1[2] -= score
	freq2[1] -= score
	sum += 2 * score
	score = min(freq1[1], freq2[0])
	freq1[1] -= score
	freq2[0] -= score
	score = min(freq1[1], freq2[1])
	freq1[1] -= score
	freq2[1] -= score
	sum -= 2 * min(freq1[1], freq2[2])
	return sum
t = int(input())
for i in range(t):
	freq1 = list(map(int, input().split()))
	freq2 = list(map(int, input().split()))
	print(answer(freq1, freq2))


a = lambda : map(int, input().split())
(b,) = a()
for _ in [0] * b:
	(x, y, z) = a()
	n = x + y + z
	(u, v, w) = a()
	print(n - max(y + w, n - min(z, v)) << 1)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(x1, y1, z1) = input_split()
	(x2, y2, z2) = input_split()
	ans = 0
	if z1 > y2:
		ans += y2
		up_anni = x1 + (z1 - y2)
		if up_anni > z2:
			pass
		else:
			ans -= z2 - up_anni
	else:
		ans += z1
		up_anni = x1
		if up_anni > z2:
			pass
		else:
			ans -= z2 - up_anni
	answers.append(2 * ans)
print(*answers, sep='\n')


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict, Counter
from math import gcd

def main():
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(2 * (min(y, c) - max(0, z - a - (c - min(y, c)))))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	main()


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


def func(a, b):
	if a < b:
		b -= a
		a = 0
	elif a == b:
		a = 0
		b = 0
	else:
		a -= b
		b = 0
	return (a, b)
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	ans = 2 * min(c, e)
	(c, e) = func(c, e)
	(c, f) = func(c, f)
	(a, f) = func(a, f)
	(b, d) = func(b, d)
	(b, e) = func(b, e)
	(a, d) = func(a, d)
	(a, e) = func(a, e)
	(c, d) = func(c, d)
	ans -= 2 * min(b, f)
	print(ans)


def ternary(x1, y1, z1, x2, y2, z2):
	ans = 0
	if z1 <= y2:
		ans += 2 * z1
		y2 -= z1
		z1 = 0
	else:
		ans += 2 * y2
		z1 -= y2
		y2 = 0
	if y1 + z2 >= (x1 + x2 + y1 + y2 + z1 + z2) // 2:
		ans += (y1 + z2 - (x1 + x2 + y1 + y2 + z1 + z2) // 2) * -2
	return ans
t = int(input())
final = []
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	final.append(ternary(x1, y1, z1, x2, y2, z2))
for _ in range(t):
	print(final[_])


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
T = int(stdin.readline())
for _ in range(T):
	da = {}
	db = {}
	(x1, y1, z1) = list(map(int, stdin.readline().rstrip().split()))
	(x2, y2, z2) = list(map(int, stdin.readline().rstrip().split()))
	t = min(y2, z1)
	ans = t * 2
	if z1 == 0:
		if y1 - (y2 - t) - x2 > 0:
			ans -= (y1 - (y2 - t) - x2) * 2
	elif z2 - (z1 - t) - x1 > 0:
		ans -= (z2 - (z1 - t) - x1) * 2
	print(ans)


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


t = int(input())
for _ in range(t):
	(x1, y1, z1) = (int(i) for i in input().split())
	(x2, y2, z2) = (int(i) for i in input().split())
	s = min(z1, y2) * 2
	zs = z1 - y2 if z1 > y2 else 0
	zt = z2 - zs - x1
	if zt > 0:
		s -= zt * 2
	print(s)


for _ in range(int(input())):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	ret = 0
	if z1 <= y2:
		y2 -= z1
		ret += z1 * 2
		z1 = 0
	else:
		z1 -= y2
		ret += y2 * 2
		y2 = 0
	if z1 <= z2:
		z2 -= z1
		z1 = 0
	else:
		z1 -= z2
		z2 = 0
	if z2 != 0:
		if z2 <= x1:
			x1 -= z2
			z2 = 0
		else:
			z2 -= x1
			x1 = 0
	if z2 and y1:
		ret -= z2 * 2
	print(ret)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(x1, y1, z1) = neo()
	(x2, y2, z2) = neo()
	Ans = 0
	Ans += 2 * min(z1, y2)
	if z1 >= y2:
		t = z1 - y2
		p = z2 - t - x1
		Ans -= 2 * max(p, 0)
	else:
		t = z2 - x1
		Ans -= 2 * max(t, 0)
	print(Ans)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	ans = 2 * min(c, e)
	if e >= c:
		if e + d >= c + b:
			print(ans)
		else:
			print(ans - 2 * (c + b - d - e))
	else:
		x = c - e
		if f - x <= a:
			print(ans)
		else:
			print(ans - 2 * (f - x - a))


def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		(x1, y1, z1) = lin()
		(x, y, z) = lin()
		y2 = min(z1, y)
		y3 = x1 + z1 - y2
		z2 = max(0, z - y3)
		sm = 2 * y2 + -2 * min(z2, y1)
		print(sm)
main()


import sys
input = lambda : sys.stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(x1, y1, z1) = mp()
	(x2, y2, z2) = mp()
	ans = 0
	pl2 = min(z1, y2)
	ans = 2 * pl2
	z1 -= pl2
	y2 -= pl2
	sub1 = min(x2 + y2, y1)
	y1 -= sub1
	x2 -= sub1
	sub2 = min(x1 + z1, z2)
	z2 -= sub2
	ans -= 2 * min(z2, y1)
	print(ans)


t = int(input())
for _ in range(t):
	(xa, ya, za) = [int(x) for x in input().split()]
	(xb, yb, zb) = [int(x) for x in input().split()]
	ans = min(za, yb)
	za -= ans
	yb -= ans
	zb = zb - xa - za
	if zb > 0:
		ans -= zb
	ans *= 2
	print(ans)


t = int(input())
for k in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	jump = min(z1, y2)
	z1 -= jump
	y2 -= jump
	sum += 2 * jump
	jump = min(x1 + z1, z2)
	z2 -= jump
	sum -= min(z2, y1) * 2
	print(sum)


t = int(input())
while t > 0:
	t -= 1
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	ans = 0
	if q >= c:
		ans += c
		q -= c
		c = 0
	else:
		ans += q
		c -= q
		q = 0
	if b <= q + p:
		b = 0
		print(2 * ans)
	else:
		b -= q + p
		ans -= min(b, r)
		print(2 * ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	(a, b, c) = inp()
	(x, y, z) = inp()
	ans = 2 * min(c, y)
	temp = min(c, y)
	c -= temp
	y -= temp
	temp = min(a, z)
	a -= temp
	z -= temp
	temp = min(c, z)
	c -= temp
	z -= temp
	ans -= 2 * min(b, z)
	print(ans)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	sm = 0
	if z != 0:
		if q != 0:
			if z >= q:
				sm += 2 * q
				z -= q
			else:
				sm += 2 * z
				z = 0
	if r != 0 and z != 0:
		if r >= z:
			r -= z
			z = 0
		else:
			r = 0
	if r != 0 and x != 0:
		if r >= x:
			r -= x
			x = 0
		else:
			r = 0
	if r != 0 and y != 0:
		sm -= 2 * r
	print(sm)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	pairs = 2 * min(z1, y2)
	left = y2 - pairs // 2 + x2
	if y1 > left:
		pairs -= 2 * (y1 - left)
	print(pairs)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(q, w, e) = map(int, input().split())
	(a, s, d) = map(int, input().split())
	k = min(e, s) * 2
	if d > q:
		if d > q + (e - min(e, s)):
			k -= (d - q - (e - min(e, s))) * 2
		else:
			pass
	print(k)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	zeros = min(z2, x1)
	z2 -= zeros
	x1 -= zeros
	zeros = min(z2, z1)
	z2 -= zeros
	z1 -= zeros
	minus2 = min(z2, y1)
	z2 -= minus2
	y1 -= minus2
	plus2 = min(z1, y2)
	print(2 * plus2 - 2 * minus2)


t = int(input())
while t != 0:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	maxi = 0
	k = min(z1, y2)
	z1 -= k
	y2 -= k
	maxi = 2 * k
	o = min(x2, y1)
	x2 -= o
	y1 -= o
	p = min(y1, y2)
	y1 -= p
	y2 -= p
	last = min(y1, z2)
	print(maxi - 2 * last)
	t -= 1


for i in range(int(input())):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	count = 0
	if b[2] > a[0] + a[2]:
		b[2] -= a[0] + a[2]
		count -= b[2] * 2
		a[0] = 0
		a[1] -= b[2]
		a[2] = 0
		b[2] = 0
		print(count)
	elif b[2] == a[2] + a[0]:
		print(0)
	elif a[0] - b[2] < 0:
		if a[2] + a[0] < b[1] + b[2]:
			count += (a[2] + a[0] - b[2]) * 2
			b[1] -= a[2] + a[0] - b[2]
			print(count)
		else:
			count += b[1] * 2
			print(count)
	elif a[2] - b[1] < 0:
		count += a[2] * 2
		print(count)
	else:
		count += b[1] * 2
		print(count)


for i in range(int(input())):
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	ans = 2 * min(x2, y1)
	m = min(y2, x0)
	(y2, x0) = (y2 - m, x0 - m)
	m = min(x1, y0)
	(x1, y0) = (x1 - m, y0 - m)
	print(ans - 2 * min(x1, y2))


for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	a = min(z1, y2)
	b = a * 2
	if a >= z1:
		pass
	else:
		z2 = z2 - (z1 - a)
	c = min(x1, z2)
	if z2 < c:
		pass
	else:
		b -= (z2 - c) * 2
	print(b)


T = int(input())
for t in range(T):
	(x1, y1, z1) = [int(x) for x in input().split(' ')]
	(x2, y2, z2) = [int(x) for x in input().split(' ')]
	score = 0
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	score += 2 * m
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(z1, z2)
	z1 -= m
	z2 -= m
	m = min(y1, x2)
	y1 -= m
	x2 -= m
	m = min(y1, y2)
	y1 -= m
	y2 -= m
	m = min(y1, z2)
	score -= 2 * m
	print(score)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	L = [x1, y1, z1]
	M = [x2, y2, z2]
	ans = 0
	val = min(z1, y2)
	z1 -= val
	y2 -= val
	ans += val * 2
	val = min(y1, y2)
	y1 -= val
	y2 -= val
	val = min(z2, x1)
	x1 -= val
	z2 -= val
	if z2 > 0 and z1 > 0:
		val = min(z1, z2)
		z1 -= val
		z2 -= val
	if z2 > 0 and y1 > 0:
		ans -= min(z2, y1) * 2
	print(ans)


import sys
from collections import defaultdict
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	x = min(c, e)
	s = 2 * x
	c -= x
	e -= x
	x = min(a, f)
	a -= x
	f -= x
	x = min(d, b)
	d -= x
	b -= x
	x = min(a, e)
	a -= x
	e -= x
	x = min(d, c)
	d -= x
	c -= x
	x = min(a, d)
	a -= x
	d -= x
	x = min(b, e)
	b -= x
	e -= x
	x = min(c, f)
	c -= x
	f -= x
	print(s - 2 * b)


for _ in range(int(input())):
	(x10, x11, x12) = map(int, input().split())
	(x20, x21, x22) = map(int, input().split())
	pos = min(x12, x21)
	x12 -= pos
	x21 -= pos
	negators = x10 + x12
	if negators > x22:
		print(pos * 2)
	else:
		print(pos * 2 - (x22 - negators) * 2)


for _ in range(int(input())):
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	s = 0
	m = min(c1, b2)
	s += 2 * m
	c1 -= m
	b2 -= m
	y = a1 + c1
	c2 -= y
	if c2 > 0:
		s -= 2 * c2
	print(s)


t = int(input())
for i in range(t):
	(n, k, l) = list(map(int, input().split()))
	(n1, k1, l1) = list(map(int, input().split()))
	c = k1 - l if l - k1 < 0 else 0
	f = 0 if n1 + c > k else (k - n1 - c) * 2
	print(min(l, k1) * 2 - f)


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)


for _ in range(int(input())):
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	sum = 0
	a = min(A[2], B[1])
	sum += 2 * a
	A[2] -= a
	B[1] -= a
	b = min(A[0], B[2])
	A[0] -= b
	B[2] -= b
	c = min(A[2], B[2])
	A[2] -= c
	B[2] -= c
	d = min(A[1], B[1])
	A[1] -= d
	B[1] -= d
	e = min(A[1], B[0])
	A[1] -= e
	B[0] -= e
	f = min(A[0], B[1])
	A[0] -= f
	B[1] -= f
	g = min(A[0], B[0])
	A[0] -= g
	B[0] -= g
	h = min(A[2], B[0])
	A[2] -= h
	B[0] -= h
	i = min(A[1], B[2])
	sum += -2 * i
	A[1] -= i
	B[2] -= i
	print(sum)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	s = 0
	(p, q, a, b, k) = (0, 0, 0, 0, 0)
	s = 0
	(m1, m2) = (0, 0)
	s1 = 0
	m1 = min(z1, y2)
	z1 -= m1
	z2 -= z1
	m2 = max(z2 - x1, 0)
	s += 2 * m1 - 2 * m2
	print(s)


import math
import os
import random
import re
import string
from sys import *
from collections import *

def bs(arr, x, l, r):
	if l <= r:
		mid = (r + l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return bs(arr, x, l, mid - 1)
		else:
			return bs(arr, x, mid + 1, r)
	else:
		return -1

def solve():
	for _ in range(int(input())):
		(a, b, c) = map(int, stdin.readline().strip().split())
		(x, y, z) = map(int, stdin.readline().strip().split())
		su1 = a + b + c
		su2 = x + y + z
		ff = min(c, y)
		s1 = 2 * min(c, y)
		c -= ff
		y -= ff
		if a + c >= z:
			s2 = 0
		else:
			s2 = 2 * (z - (a + c))
		print(s1 - s2)
solve()


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z3) = map(int, input().split())
	q = min(z1, y2)
	cnt = 2 * q
	z1 -= q
	y2 -= q
	w = min(x1, z3)
	z3 -= w
	x1 -= w
	e = min(z1, z3)
	z3 -= e
	z1 -= e
	if z3 > 0:
		e = min(y1, z3)
		cnt = cnt - 2 * e
	print(cnt)


for j in range(int(input())):
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	su = 0
	if li1[2] > li2[1]:
		if li2[2] > li1[0] + (li1[2] - li2[1]):
			su = li2[2] - (li1[0] + (li1[2] - li2[1]))
			su = su * 2
			print(li2[1] * 2 - su)
		else:
			print(li2[1] * 2)
	elif li1[2] <= li2[1]:
		if li2[2] > li1[0]:
			su = li2[2] - li1[0]
			su = su * 2
			print(li1[2] * 2 - su)
		else:
			print(li1[2] * 2)


from sys import stdin, stdout, setrecursionlimit

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(x1, y1, z1) = [int(x) for x in R().split()]
			(x2, y2, z2) = [int(x) for x in R().split()]
			max_sum = 0
			mn = min(z1, y2)
			z1 -= mn
			y2 -= mn
			max_sum += 2 * mn
			mn = min(z1, z2)
			z1 -= mn
			z2 -= mn
			mn = min(z1, x2)
			z1 -= mn
			x2 -= mn
			mn = min(y1, y2)
			y1 -= mn
			y2 -= mn
			mn = min(y1, x2)
			y1 -= mn
			x2 -= mn
			mn = min(y1, z2)
			y1 -= mn
			z2 -= mn
			max_sum -= 2 * mn
			mn = min(x1, z2)
			x1 -= mn
			z2 -= mn
			ans.append(str(max_sum))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


import sys
read = lambda : sys.stdin.readline().strip()

def getSum(x1, y1, z1, x2, y2, z2):
	if z2 <= x1:
		return min(z1, y2) * 2
	else:
		z2 = z2 - x1
		x1 = 0
		if z1 >= z2:
			return min(z1 - z2, y2) * 2
		else:
			z2 = z2 - z1
			z1 = 0
			return -2 * min(y1, z2)
for _ in range(int(read())):
	(x1, y1, z1) = map(int, read().split())
	(x2, y2, z2) = map(int, read().split())
	print(getSum(x1, y1, z1, x2, y2, z2))


def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = min(z1, y2) * 2
	if z1 < y2:
		y2 = y2 - z1
		z1 = 0
	else:
		z1 = z1 - y2
		y2 = 0
	if y1 > x2 + y2:
		ans -= (y1 - (x2 + y2)) * 2
	print(ans)

def main():
	for i in range(int(input())):
		solve()
main()


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	a = inara()
	b = inara()
	mini = min(a[-1], b[1])
	ans = 2 * mini
	a[-1] -= mini
	b[1] -= mini
	mini = min(a[0], b[-1])
	a[0] -= mini
	b[-1] -= mini
	mini = min(a[1], b[0])
	a[1] -= mini
	b[0] -= mini
	mini = min(a[1], b[1])
	a[1] -= mini
	b[1] -= mini
	mini = min(a[-1], b[-1])
	a[-1] -= mini
	b[-1] -= mini
	ans -= 2 * min(a[1], b[-1])
	print(ans)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	first = min(a[2], b[1])
	ans += 2 * first
	a[2] -= first
	b[1] -= first
	second = min(a[1], b[0])
	a[1] -= second
	b[0] -= second
	third = min(a[0], b[2])
	a[0] -= third
	b[2] -= third
	fourth = min(a[1], b[2])
	ans -= 2 * fourth
	print(ans)


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
	p = min(z1, y2)
	ans += 2 * p
	z1 -= p
	y2 -= p
	q = z1 + x1
	z2 -= min(z2, q)
	r = min(z2, y1)
	ans -= 2 * r
	print(ans)


t = int(input())
for ii in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 0
	if a2 >= b1:
		a2 -= b1
		ans += 2 * b1
		b1 = 0
	else:
		ans += 2 * a2
		b1 -= a2
		a2 = 0
	if a2 > 0:
		if a2 >= b2:
			a2 -= b2
			b2 = 0
		else:
			b2 -= a2
			a2 = 0
	if a2 > 0:
		if a2 >= b0:
			a2 -= b0
			b0 = 0
		else:
			b0 -= a2
			a2 = 0
	if a1 > 0:
		if a1 >= b1 + b0:
			a1 -= b1 + b0
			b1 = 0
			b0 = 0
			ans -= 2 * a1
			b2 -= a1
			a1 = 0
		elif a1 >= b1:
			a1 -= b1
			b1 = 0
			b0 -= a1
			a1 = 0
		else:
			b1 -= a1
			a1 = 0
	print(ans)


for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a2 = []
	b2 = []
	(a[0], b[2]) = (a[0] - min(a[0], b[2]), b[2] - min(a[0], b[2]))
	(a[2], b[1], counter) = (a[2] - min(a[2], b[1]), b[1] - min(a[2], b[1]), min(a[2], b[1]) * 2)
	(a[2], b[2]) = (a[2] - min(a[2], b[2]), b[2] - min(a[2], b[2]))
	(a[1], b[0]) = (a[1] - min(a[1], b[0]), b[0] - min(a[1], b[0]))
	(a[1], b[1]) = (a[1] - min(a[1], b[1]), b[1] - min(a[1], b[1]))
	counter -= a[1] * 2
	print(counter)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	m1 = min(z1, y2)
	np = 2 * m1
	z1 = z1 - m1
	y2 = y2 - m1
	m2 = z2 - (x1 + z1)
	if m2 > 0:
		nn = -2 * m2
	else:
		nn = 0
	print(np + nn)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	mint = min(y2, z1)
	z1 -= mint
	y2 -= mint
	suu = mint * 2
	if x1 + z1 < z2:
		su = (z2 - (x1 + z1)) * 2
		suu -= su
	print(suu)


for ad in range(int(input())):
	(a0, a1, a2) = list(map(int, input().split()))
	(b0, b1, b2) = list(map(int, input().split()))
	ans = 0
	if a2 >= b1:
		ans += 2 * b1
		a2 -= b1
		if b2 <= a2:
			pass
		else:
			b2 -= a2
			if b2 <= a0:
				pass
			else:
				b2 -= a0
				ans -= b2 * 2
	else:
		ans += 2 * a2
		if b2 <= a0:
			pass
		else:
			b2 -= a0
			ans -= 2 * b2
	print(ans)


import math
for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = min(z1, y2) * 2
	if z1 >= y2:
		if y1 > x2:
			ans -= min(y1 - x2, z2) * 2
	elif y1 > x2 + y2 - z1:
		ans -= min(y1 - x2 - y2 + z1, z2) * 2
	print(ans)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(a, b, c) = int_array()
	(x, y, z) = int_array()
	twos_used = min(c, y)
	ans = 2 * twos_used
	twos_left = c - twos_used
	if twos_left + a < z:
		ones_to_use = z - a - twos_left
		ans -= 2 * ones_to_use
	print(ans)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		ar = inpt()
		br = inpt()
		ans = 0
		ans = 0
		mn = min(ar[0], br[2])
		ar[0] -= mn
		br[2] -= mn
		mn = min(ar[2], br[2])
		ar[2] -= mn
		br[2] -= mn
		mn = min(ar[1], br[0])
		ar[1] -= mn
		br[0] -= mn
		mn = min(ar[2], br[1])
		ans += mn * 2
		ar[2] -= mn
		br[1] -= mn
		mn = min(ar[1], br[2])
		ans -= mn * 2
		br[2] -= mn
		ar[1] -= mn
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
I = stdin.readline
for _ in range(int(I())):
	a = list(map(int, I().split()))
	b = list(map(int, I().split()))
	temp = min(a[2], b[1])
	ans = temp * 2
	a[2] -= temp
	b[1] -= temp
	temp = min(a[2], b[2])
	a[2] -= temp
	b[2] -= temp
	temp = min(a[0], b[2])
	a[0] -= temp
	b[2] -= temp
	temp = min(a[1], b[2])
	ans -= temp * 2
	print(ans)


for i in range(int(input())):
	s = [int(i) for i in input().split()]
	d = [int(i) for i in input().split()]
	a = min(d[1], s[2])
	cnt = a * 2
	d[1] -= a
	s[2] -= a
	d[2] -= min(d[2], s[0] + s[2])
	cnt -= min(s[1], d[2]) * 2
	print(cnt)


t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	Sum = 0
	sub = 0
	if z1 <= y2:
		Sum = 2 * z1
		z1 = 0
	else:
		Sum = 2 * y2
		z1 = z1 - y2
	if z1 + x1 <= z2:
		z2 = z2 - (z1 + x1)
		sub = 2 * z2
	print(Sum - sub)


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


t = int(input())
for tc in range(t):
	line1 = input().split()
	line2 = input().split()
	(x1, y1, z1) = (int(line1[0]), int(line1[1]), int(line1[2]))
	(x2, y2, z2) = (int(line2[0]), int(line2[1]), int(line2[2]))
	posi = min(z1, y2)
	if z1 > y2:
		z1 -= posi
		y2 = 0
	elif y2 > z1:
		y2 -= posi
		z1 = 0
	else:
		y2 = 0
		z1 = 0
	z2 -= z1 + x1
	if z2 <= 0:
		ans = 2 * posi
	else:
		ans = 2 * posi - 2 * min(z2, y1)
	print(ans)


for i in range(int(input())):
	(x_1, y_1, z_1) = map(int, input().split())
	(x_2, y_2, z_2) = map(int, input().split())
	n = min(z_1, y_2)
	y_2 = y_2 - n
	z_1 = z_1 - n
	if y_1 <= x_2 + y_2:
		print(2 * n)
	else:
		print(2 * n - 2 * (y_1 - x_2 - y_2))


def solve(x1, y1, z1, x2, y2, z2):
	if x1 != 0:
		if y2 != 0:
			a = min(x1, y2)
			return 2 * a + solve(x1 - a, y1, z1, x2, y2 - a, z2)
		elif x2 >= x1:
			return solve(0, y1, z1, x2 - x1, y2, z2)
		else:
			return solve(0, y1, z1, 0, y2, z2 - x1 + x2)
	elif y1 != 0:
		if y2 + z2 != 0:
			a = min(y1, y2 + z2)
			if y2 >= a:
				return solve(0, y1 - a, z1, x2, y2 - a, z2)
			else:
				return solve(0, y1 - a, z1, x2, 0, z2 - a + y2)
		else:
			return -2 * y1 + solve(0, 0, z1, x2 - y1, 0, 0)
	else:
		return 0
t = int(input())
for _ in range(t):
	(x1, y1, z1) = (int(x) for x in input().split())
	(x2, y2, z2) = (int(x) for x in input().split())
	print(solve(z1, y1, x1, z2, y2, x2))


t = int(input())
while t > 0:
	in1 = list(map(int, input().split()))
	in2 = list(map(int, input().split()))
	suma = 0
	m = min(in1[0], in2[2])
	in1[0] -= m
	in2[2] -= m
	m = min(in1[1], in2[0])
	in1[1] -= m
	in2[0] -= m
	m = min(in1[2], in2[1])
	in1[2] -= m
	in2[1] -= m
	suma += 2 * m
	m = min(in1[1], in2[2])
	in1[1] -= m
	in2[2] -= m
	suma += -2 * m
	print(suma)
	t -= 1


def f(a, b, c, d, e, g):
	m = min(c, e)
	k = max(0, b - (d + e - m))
	return 2 * (m - k)
numberofcases = int(input())
for _ in range(numberofcases):
	(a, b, c) = [int(t) for t in input().split()]
	(d, e, g) = [int(t) for t in input().split()]
	print(f(a, b, c, d, e, g))


t = int(input())
while t:
	sum_all = 0
	(x_1, y_1, z_1) = [int(e) for e in input().split()]
	(x_2, y_2, z_2) = [int(e) for e in input().split()]
	mn = min(z_1, y_2)
	sum_all += 2 * mn
	z_1 -= mn
	y_2 -= mn
	mn = min(z_2, x_1)
	z_2 -= mn
	x_1 -= mn
	mn = min(z_1, z_2)
	z_1 -= mn
	z_2 -= mn
	mn = min(z_2, y_1)
	sum_all -= 2 * mn
	z_2 -= mn
	y_1 -= mn
	print(sum_all)
	t -= 1


def solve(a, b):
	x = min(a[2], b[1]) * 2 - max(min([a[2] + a[1] - b[1] - b[0], a[1], b[2]]), 0) * 2
	y = min(a[2], b[1]) * 2 - max(min([b[1] + b[2] - a[2] - a[0], a[1], b[2]]), 0) * 2
	return max(x, y)
n = int(input())
for _ in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	val = 2 * min(c, e)
	diff = min(c, e)
	c = c - diff
	e = e - diff
	diff = min(a, f)
	a = a - diff
	f = f - diff
	diff = min(a, e)
	a = a - diff
	e = e - diff
	diff = min(d, b)
	d = d - diff
	b = b - diff
	diff = min(b, e)
	b = b - diff
	e = e - diff
	nn = 2 * min(b, f)
	val = val - nn
	print(val)


t = int(input())
for i in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 0
	if a2 > b1:
		ans += b1 * 2
		a2 -= b1
		b1 = 0
	else:
		ans += a2 * 2
		b1 -= a2
		a2 = 0
	if b2 == 0:
		print(ans)
		continue
	if a1 > b1:
		a1 -= b1
		b1 = 0
	else:
		b1 -= a1
		a1 = 0
	if a0 > b2:
		a0 -= b2
		b2 = 0
	else:
		b2 -= a0
		a0 = 0
	if b2 == 0:
		print(ans)
		continue
	if a2 > b2:
		a2 -= b2
		b2 = 0
	else:
		b2 -= a2
		a2 = 0
	if b2 == 0:
		print(ans)
		continue
	if a1 > b0:
		a1 -= b0
		b0 = 0
	else:
		b0 -= a1
		a1 = 0
	if b2 > a1:
		ans -= a1 * 2
		b2 -= a1
		a1 = 0
	else:
		ans -= b2 * 2
		a1 -= b2
		b2 = 0
	if b2 == 0:
		print(ans)


t = int(input())
for _ in range(t):
	(c1, b1, a1) = list(map(lambda x: int(x), input().split()))
	(c2, b2, a2) = list(map(lambda x: int(x), input().split()))
	s = 0
	s = s + min(a1, b2) * 2
	(a1, b2) = (a1 - min(a1, b2), b2 - min(a1, b2))
	(b1, c2) = (b1 - min(b1, c2), c2 - min(b1, c2))
	(b1, b2) = (b1 - min(b1, b2), b2 - min(b1, b2))
	(c1, a2) = (c1 - min(c1, a2), a2 - min(c1, a2))
	if b1 != 0 and a2 != 0:
		s = s - min(b1, a2) * 2
	print(s)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def f(a, b):
	if a == b:
		return (0, 0)
	elif a > b:
		return (a - b, 0)
	else:
		return (0, b - a)
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 2 * min(z1, y2)
	(z1, y2) = f(z1, y2)
	(z1, z2) = f(z1, z2)
	(z1, x2) = f(z1, x2)
	(x1, z2) = f(z1, z2)
	(x1, y2) = f(x1, y2)
	(x1, x2) = f(x1, x2)
	(y1, x2) = f(y1, x2)
	(y1, y2) = f(y1, y2)
	if y1 != 0:
		ans -= 2 * abs(y1)
		y1 = 0
	print(ans)


import random
t = int(input())
for q in range(t):
	ch = input()
	A = [int(i) for i in ch.split()]
	ch = input()
	B = [int(i) for i in ch.split()]
	(a1, a2, a3) = (A[0], A[1], A[2])
	(b1, b2, b3) = (B[0], B[1], B[2])
	s = 0
	x = min(a3, b2)
	s += 2 * x
	a3 -= x
	b2 -= x
	x = min(a3, b3)
	a3 -= x
	b3 -= x
	x = min(a3, b1)
	a3 -= x
	b1 -= x
	x = min(a2, b2)
	a2 -= x
	b2 -= x
	x = min(a2, b1)
	a2 -= x
	b1 -= x
	x = min(a2, b3)
	a2 -= x
	b1 -= x
	s -= 2 * x
	print(s)


import sys
readline = sys.stdin.buffer.readline

def even(n):
	return 1 if n % 2 == 0 else 0
query = int(readline())

def func(a, b):
	ans = 0
	res = min(a[2], b[1])
	a[2] -= res
	b[1] -= res
	ans += 2 * res
	for i in [1, 0, 2]:
		for j in [2, 1, 0]:
			if i == 1 and j == 2:
				continue
			res = min(a[i], b[j])
			a[i] -= res
			b[j] -= res
	if a[1] != b[2]:
		raise Exception
	ans -= 2 * a[1]
	print(ans)
for _ in range(query):
	lst1 = list(map(int, readline().split()))
	lst2 = list(map(int, readline().split()))
	func(lst1, lst2)


for p in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	z -= a
	if z < 0:
		z = 0
	if c >= z:
		c -= z
		s = min(c, y) * 2
	else:
		z -= c
		s = min(z, b) * 2 * -1
	print(s)


import sys
from math import sqrt
from collections import OrderedDict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def invr():
	return map(int, inpt().split())

class node(object):

	def __init__(self, x, p, h):
		(self.x, self.p, self.h) = (x, p, h)
		self.children = []

	def add_child(self, obj):
		self.children.append(obj)

def main():
	t = inp()
	for l in range(t):
		(x1, y1, z1) = invr()
		(x2, y2, z2) = invr()
		ans = 0
		plus = min(z1, y2)
		ans += 2 * plus
		z1 -= plus
		y2 -= plus
		if y1 > x2 + y2:
			ans -= 2 * (y1 - (x2 + y2))
		print(ans)
main()


n = int(input())
for i in range(n):
	ans = 0
	a = {i: int(x) for (i, x) in enumerate(input().split())}
	b = {i: int(x) for (i, x) in enumerate(input().split())}
	val = min(a[2], b[1])
	b[1] = b[1] - val
	ans += 2 * val
	val2 = min(a[1], b[0] + b[1])
	a[1] = a[1] - val2
	ans = ans - 2 * a[1]
	print(ans)


for _ in range(int(input())):
	f = list(map(int, input().split()))
	s = list(map(int, input().split()))
	t = 0

	def ng(i, g):
		global t
		if i > g:
			d = min(f[i], s[g])
			f[i] -= d
			s[g] -= d
			t += i * g * d
		elif i == g:
			d = min(f[i], s[g])
			f[i] -= d
			s[g] -= d
		else:
			d = min(f[i], s[g])
			t -= i * g * d
			f[i] -= d
			s[g] -= d
	ng(0, 2)
	ng(2, 2)
	ng(1, 2)
	ng(2, 1)
	print(t)


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


t = int(input())
ans = []
while t:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z3) = map(int, input().split())
	c = 0
	abp = min(z1, y2)
	c = c + abp * 2
	z3 = z3 - min(z3, x1)
	y1 = y1 - min(x2, y1)
	abn = min(z3, y1)
	c = c - abn * 2
	ans.append(c)
	t = t - 1
for i in ans:
	print(i)


def main():
	t = int(input())
	for _ in range(t):
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		sc = 0
		k = min(a[2], b[1])
		sc += k * 2
		a[2] -= k
		b[1] -= k
		k = min(a[1], b[1])
		a[1] -= k
		b[1] -= k
		k = min(a[1], b[0])
		a[1] -= k
		b[0] -= k
		k = min(a[2], b[2])
		a[2] -= k
		b[2] -= k
		k = min(a[0], b[2])
		a[0] -= k
		b[2] -= k
		k = min(a[1], b[2])
		sc -= k * 2
		a[1] -= k
		b[2] -= k
		k = min(a[0], b[1])
		a[0] -= k
		b[1] -= k
		k = min(a[0], b[0])
		a[0] -= k
		b[0] -= k
		k = min(a[2], b[0])
		a[2] -= k
		b[0] -= k
		print(sc)
	return
main()


t = input()
t = int(t)

def solve(x1, y1, z1, x2, y2, z2):
	c = 0
	if z1 >= y2:
		c += 2 * y2
		if x1 + (z1 - y2) < z2:
			c -= 2 * (z2 - x1 - z1 + y2)
	else:
		c += 2 * z1
		if x1 < z2:
			c -= 2 * (z2 - x1)
	print(c)
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	solve(x1, y1, z1, x2, y2, z2)


for n in range(int(input())):
	(x, y, z) = map(int, input().split())
	(x1, y1, z1) = map(int, input().split())
	ans = 0
	if x >= z1:
		x -= z1
		z1 = 0
	else:
		z1 -= x
		x = 0
	if y >= x1:
		y -= x1
		x1 = 0
	else:
		x1 -= y
		y = 0
	if z >= y1:
		z -= y1
		ans += 2 * y1
		y1 = 0
	else:
		y1 -= z
		ans += 2 * z
		z = 0
	if y >= z1:
		y -= z1
		ans += -2 * z1
	else:
		z1 -= y
		ans += -2 * y
	print(ans)


t = int(input())
for i in range(t):
	(a, a_o, a_t) = map(int, input().split())
	(b, b_o, b_t) = map(int, input().split())
	if b_t >= a:
		b_t -= a
		if b_t >= a_t:
			b_t -= a_t
			print(b_t * -2)
		else:
			a_t -= b_t
			print(min(a_t, b_o) * 2)
	else:
		a -= b_t
		print(min(a_t, b_o) * 2)


t = int(input())
for _ in range(t):
	(x1, x2, x3) = map(int, input().split(' '))
	(y1, y2, y3) = map(int, input().split(' '))
	ans = 0
	ans += min(x3, y2) * 2
	x3 -= min(x3, y2)
	y2 -= min(x3, y2)
	if x3 != 0 and x3 >= y3:
		y3 = 0
		x3 -= y3
		y1 -= x3
	else:
		y3 -= x3
		x3 = 0
	y3 -= min(y3, x1)
	x1 -= min(y3, x1)
	ans += min(y3, x2) * -2
	print(ans)


t = int(input())
i = 0
while i < t:
	xyz1 = list(map(int, input().split()))
	xyz2 = list(map(int, input().split()))
	x1 = xyz1[0]
	y1 = xyz1[1]
	z1 = xyz1[2]
	x2 = xyz2[0]
	y2 = xyz2[1]
	z2 = xyz2[2]
	if z1 >= y2:
		p = z2 - (z1 - y2) - x1
		if p < 0:
			ans = y2 * 2
		else:
			ans = y2 * 2 - p * 2
	else:
		d = y1 - (y2 - z1)
		if d >= 0:
			p = z2 - x1
			if p < 0:
				ans = z1 * 2
			else:
				ans = z1 * 2 - p * 2
		else:
			ans = z1 * 2
	print(ans)
	i += 1


t = int(input())
for i in range(t):
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	ans = 0
	ans += min(lst1[2], lst2[1]) * 2
	if lst1[2] > lst2[1]:
		lst1[2] -= lst2[1]
		lst2[1] = 0
		if lst1[0] >= lst2[2]:
			ans += 0
		else:
			lst2[2] -= lst1[0]
			if lst1[2] >= lst2[2]:
				ans += 0
			else:
				lst2[2] -= lst1[2]
				ans -= lst2[2] * 2
	elif lst1[2] < lst2[1]:
		lst2[1] -= lst1[2]
		lst1[2] = 0
		if lst1[0] >= lst2[2]:
			ans += 0
		else:
			lst2[2] -= lst1[0]
			ans -= lst2[2] * 2
	elif lst1[0] >= lst2[2]:
		ans += 0
	else:
		lst2[2] -= lst1[0]
		ans -= lst2[2] * 2
	print(ans)


from sys import stdin, stdout

def find(A, B):
	r = 0
	x = min(A[2], B[1])
	B[1] -= x
	A[2] -= x
	r += 2 * x
	x = min(B[2], A[2])
	B[2] -= x
	A[2] -= x
	x = min(B[1], A[1])
	A[1] -= x
	B[1] -= x
	x = min(B[2], A[0])
	B[2] -= x
	A[0] -= x
	x = min(B[0], A[1])
	B[0] -= x
	A[1] -= x
	x = min(B[2], A[1])
	return r - 2 * x

def main():
	for _ in range(int(stdin.readline())):
		A = list(map(int, stdin.readline().split()))
		B = list(map(int, stdin.readline().split()))
		print(find(A, B))
main()


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())


def good(a, b):
	s = 0
	br = False
	s = 0
	y = min(b[2], a[0])
	b[2] -= y
	a[0] -= y
	if a[0]:
		l = min(b[0], a[0])
		b[0] -= l
		a[0] -= l
	if a[0]:
		b[1] -= a[0]
	j = min(b[1], a[2])
	a[2] -= j
	b[1] -= j
	s += 2 * j
	if a[2]:
		l = min(b[2], a[2])
		b[2] -= l
		a[2] -= l
	h = min(a[1], b[2])
	a[1] -= h
	s -= 2 * h
	return s
for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(good(a, b))


t = int(input())
while t > 0:
	t = t - 1
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = min(z1, y2)
	s = 0
	s += 2 * c
	z1 = z1 - c
	y2 = y2 - c
	d = min(y1, y2)
	y1 = y1 - d
	y2 = y2 - d
	e = min(y1, x2)
	y1 = y1 - e
	x1 = x1 - e
	f = min(z1, z2)
	z1 = z1 - f
	z2 = z2 - f
	g = min(x1, z2)
	x1 = x1 - g
	z2 = z2 - g
	if y1 > 0 and z2 > 0:
		s -= min(y1, z2) * 2
	print(s)


t = int(input())
outs = []
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	out = 0
	if z1 >= y2:
		out += 2 * y2
		z1 -= y2
		y2 = 0
		if z1 >= z2:
			z1 -= z2
			z2 = 0
			if z1 >= x2:
				z2 -= x2
			else:
				x2 -= z2
		else:
			z2 -= z1
	else:
		out += 2 * z1
		y2 -= z1
	if y1 >= y2:
		y1 -= y2
		if y1 >= x2:
			y1 -= x2
			if y1 >= z2:
				out -= 2 * z2
			else:
				out -= 2 * y1
	outs.append(out)
for out in outs:
	print(out)


T = int(input())
for i in range(T):
	(x1, x2, x3) = list(map(int, input().split()))
	(y1, y2, y3) = list(map(int, input().split()))
	sum = 0
	m = min(x1, y3)
	x1 -= m
	y3 -= m
	m = min(x2, y1)
	x2 -= m
	y1 -= m
	m = min(x3, y2)
	x3 -= m
	y2 -= m
	sum += 2 * m
	sum -= 2 * min(x2, y3)
	print(sum)


t = int(input())
res = []
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	if z1 > y2:
		res.append(2 * (y2 - max(0, y1 - x2)))
	else:
		res.append(2 * (z1 - max(0, y1 + z1 - x2 - y2)))
for v in res:
	print(v)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

def inIList():
	return list(map(int, input().split()))

def inSList():
	return input().split()

def solve(n, k):
	if b[2] >= a[0] + a[2]:
		return -2 * (b[2] - (a[0] + a[2]))
	else:
		return 2 * min(a[0] + a[2] - b[2], min(b[1], a[2]))
tests = inInt()
for t in range(tests):
	a = inIList()
	b = inIList()
	print(solve(a, b))


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	pairs = min(z1, y2)
	result = pairs * 2
	z1 -= pairs
	y2 -= pairs
	pairs = min(x1, z2)
	x1 -= pairs
	z2 -= pairs
	if z1 != 0 and z2 != 0:
		pairs = min(z1, z2)
		z1 -= pairs
		z2 -= pairs
	pairs = min(y1, z2)
	result -= pairs * 2
	print(result)


from sys import stdin
from collections import defaultdict
input = stdin.readline
t = int(input())
for _ in range(t):
	(x1, y1, z1) = list(map(int, input().rstrip().split()))
	(x2, y2, z2) = list(map(int, input().rstrip().split()))
	answer = 0
	answer += 2 * min(z1, y2)
	rem2 = z1 - min(z1, y2)
	remneg2 = max(z2 - (rem2 + x1), 0)
	answer -= remneg2 * 2
	print(answer)


def solve(a, b, c, d, e, f):
	sm = 0
	while f > 0:
		if a > 0:
			x = min(a, f)
			f -= x
			a -= x
		elif c > 0:
			x = min(c, f)
			f -= x
			c -= x
		else:
			x = min(b, f)
			f -= x
			b -= x
			sm -= 2 * x
	while e > 0:
		if c > 0:
			x = min(c, e)
			e -= x
			c -= x
			sm += 2 * x
		elif a > 0:
			x = min(a, e)
			e -= x
			a -= x
		else:
			x = min(b, e)
			e -= x
			b -= x
	return sm
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	print(solve(a, b, c, d, e, f))


a = []
b = []
score = 0

def test_pairs(_t1, _t2, _toadd):
	global a, b, score
	if a[_t1] > 0 and b[_t2] > 0:
		if a[_t1] > b[_t2]:
			score += b[_t2] * _toadd
			a[_t1] -= b[_t2]
			b[_t2] = 0
		else:
			score += a[_t1] * _toadd
			b[_t2] -= a[_t1]
			a[_t1] = 0
for i in range(int(input())):
	ta = input()
	tb = input()
	a = list(map(int, ta.split()))
	b = list(map(int, tb.split()))
	score = 0
	test_pairs(2, 1, 2)
	test_pairs(0, 2, 0)
	test_pairs(0, 1, 0)
	test_pairs(0, 0, 0)
	test_pairs(1, 1, 0)
	test_pairs(2, 2, 0)
	test_pairs(1, 2, -2)
	print(score)


def f(l1, l2):
	(a0, a1, a2) = l1
	(b0, b1, b2) = l2
	a2b1 = min(a2, b1)
	a2 -= a2b1
	b1 -= a2b1
	a1b2 = max(0, b2 - a0 - a2)
	return a2b1 - a1b2 << 1
q = int(input())
for _ in range(q):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	print(f(l1, l2))


t = int(input())
while t > 0:
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	if a[1] <= b[0] + (b[1] - min(a[2], b[1])):
		print(min(a[2], b[1]) * 2)
	else:
		print((a[1] - (b[0] + (b[1] - min(a[2], b[1])))) * -2 + min(a[2], b[1]) * 2)
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def main():
	for t in range(int(input())):
		(x3, y3, z3) = map(int, input().split())
		(x4, y4, z4) = map(int, input().split())
		(x, y, z) = (z3, y3, x3)
		(x1, y1, z1) = (z4, y4, x4)
		a = min(x, y1)
		x = x - a
		y1 = y1 - a
		ans = 2 * a
		if x > 0:
			x1 = x1 - x
		x1 = x1 - min(x1, z)
		if x1 > 0:
			ans = ans - 2 * x1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		ans = 0
		(a, b, c) = map(int, input().split())
		(a1, b1, c1) = map(int, input().split())
		if a >= c1:
			a -= c1
			c1 = 0
		else:
			c1 -= a
			a = 0
		if c1 == 0:
			print(min(c, b1) * 2)
		else:
			if b1 <= c:
				ans += b1 * 2
				c -= b1
				b1 = 0
			else:
				ans += c * 2
				b1 -= c
				c = 0
			c1 = max(0, c1 - (a + c))
			ans -= c1 * 2
			print(ans)


import sys
li = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : sys.stdin.readline().strip().split()
ni = lambda : int(sys.stdin.readline().strip())
nsi = lambda : sys.stdin.readline().strip()
from collections import defaultdict as df
from math import *
t = ni()
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 0
	if b2 >= a0 + a2:
		ans = (b2 - (a0 + a2)) * -2
	elif a0 >= b2:
		ans = 2 * min(a2, b1)
	elif a0 < b2:
		a2 -= b2 - a0
		ans = 2 * min(a2, b1)
	print(ans)


import sys
input = sys.stdin.buffer.readline

def solution():
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	ans = 0
	m = min(x0, y2)
	x0 -= m
	y2 -= m
	m = min(x1, y0)
	x1 -= m
	y0 -= m
	m = min(x2, y1)
	ans += 2 * m
	ans -= 2 * min(y2, x1)
	print(ans)
t = int(input())
for _ in range(t):
	solution()


for t in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	while a[0]:
		if b[2]:
			d = min(b[2], a[0])
			a[0] -= d
			b[2] -= d
		elif b[0]:
			dd = min(b[0], a[0])
			a[0] -= dd
			b[0] -= dd
		else:
			dd = min(b[1], a[0])
			a[0] -= dd
			b[1] -= dd
	while a[1]:
		if b[0]:
			d = min(b[0], a[1])
			a[1] -= d
			b[0] -= d
		elif b[1]:
			dd = min(b[1], a[1])
			a[1] -= dd
			b[1] -= dd
		else:
			dd = min(b[2], a[1])
			ans -= 2 * dd
			a[1] -= dd
			b[2] -= dd
	d = min(b[1], a[2])
	ans += 2 * d
	print(ans)


x = int(input())
for z in range(x):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	if z1 < y2:
		ans = ans + 2 * z1
		z1 = 0
		y2 = y2 - z1
	else:
		ans = ans + 2 * y2
		z1 = z1 - y2
		y2 = 0
	if x1 > z2:
		x1 = x1 - z2
		z2 = 0
	else:
		z2 = z2 - x1
		x1 = 0
	if z1 > z2:
		print(ans)
	else:
		print(ans - 2 * (z2 - z1))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())
sys.setrecursionlimit(1500)

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def main():
	try:
		(a0, a1, a2) = In()
		(b0, b1, b2) = In()
		ans = 0
		p = 1
		while a2 > 0:
			if b1 > 0 and a2 > 0:
				temp = min(b1, a2)
				ans += 2 * temp
				b1 -= temp
				a2 -= temp
			if a2 > 0 and b2 > 0:
				temp = min(a2, b2)
				a2 -= temp
				b2 -= temp
			if a2 > 0 and b0 > 0:
				temp = min(b0, a2)
				a2 -= temp
				b0 -= temp
		while a1 > 0:
			if a1 > 0 and b1 > 0:
				temp = min(a1, b1)
				a1 -= temp
				b1 -= temp
			if a1 > 0 and b0 > 0:
				temp = min(a1, b0)
				a1 -= temp
				b0 -= temp
			if a1 > 0 and b2 > 0:
				temp = min(a1, b2)
				ans -= 2 * temp
				b2 -= temp
				a1 -= temp
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = min(a[2], b[1])
	q = max(0, a[2] - p)
	ans = p * 2
	if q + a[0] >= b[2]:
		print(ans)
	else:
		s = (b[2] - (a[0] + q)) * 2
		print(ans - s)


from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.read().splitlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx]
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

class Problem:

	def __init__(self):
		self.oo = float('inf')

	def solve(self, a, b):
		m = min(a[2], b[1])
		a[2] -= m
		b[1] -= m
		s = 2 * m
		m = min(a[2], b[2])
		b[2] -= m
		a[2] -= m
		m = min(a[0], b[2])
		b[2] -= m
		a[0] -= m
		m = min(a[1], b[0])
		b[0] -= m
		a[1] -= m
		m = min(a[1], b[1])
		b[1] -= m
		a[1] -= m
		m = min(a[1], b[2])
		s -= 2 * m
		print(s)
try:
	p = Problem()
	for tc in Input().known_tests():
		p.solve(tc.array(), tc.array())
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


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


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum1 = abs(a[2] - b[1])
	ret = 0
	if a[2] != 0 and b[1] != 0:
		if a[2] > b[1]:
			ret = b[1]
			a[2] = sum1
			b[1] = 0
		elif a[2] < b[1]:
			ret = a[2]
			a[2] = 0
			b[1] = sum1
		else:
			ret = a[2]
			(a[2], b[1]) = (0, 0)
	t_asum = sum(a)
	t_bsum = sum(b)
	sum2 = abs(b[2] - a[2] - a[0])
	if b[2] > a[2] + a[0]:
		ret -= sum2
	print(ret * 2)


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()))
	result = min(a[2], b[1]) * 2
	a[2] -= min(a[2], b[1])
	b[2] -= min(a[0], b[2])
	result -= (b[2] - min(a[2], b[2])) * 2
	print('%d\n' % result)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, atan
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
for _ in range(int(inp())):
	x = lmp()
	y = lmp()
	cnt = 0
	cnt += 2 * min(x[2], y[1])
	x[1] -= min(x[1], y[0])
	y[2] -= min(y[2], x[0])
	cnt -= 2 * min(x[1], y[2])
	print(cnt)


t = int(input())
for i in range(0, t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	summ = 0
	x = min(z1, y2)
	summ = summ + 2 * x
	z1 = z1 - x
	y2 = y2 - x
	y = min(x1, z2)
	x1 = x1 - y
	z2 = z2 - y
	kk = min(y1, x1)
	y1 = y1 - kk
	x1 = x1 - kk
	kl = min(y1, y2)
	y1 = y1 - kl
	y2 = y2 - kl
	kk1 = min(z2, z1)
	z2 = z2 - kk1
	z1 = z1 - kk1
	kk2 = min(y1, z2)
	summ = summ - 2 * kk2
	print(summ)


import sys
pprint = lambda s: print(' '.join(map(lambda x: str(x), s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for _ in range(int(input())):
	(z1, o1, t1) = map(int, input().split())
	(z2, o2, t2) = map(int, input().split())
	ans = 0
	x = min(o2, t1)
	t1 -= x
	o2 -= x
	ans += x * 2
	x = min(z1, t2)
	z1 -= x
	t2 -= x
	x = min(t1, t2)
	t1 -= x
	t2 -= x
	x = min(o1, t2)
	o1 -= x
	t2 -= x
	ans -= x * 2
	print(ans)


t = int(input())
for _ in range(t):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	c = 0
	val = min(a2, b1)
	c += 2 * val
	a2 -= val
	b1 -= val
	val = min(b2, a0)
	b2 -= val
	a0 -= val
	if b2 > a2 + a0:
		c -= 2 * min(b2 - a2 - a0, a1)
	print(c)


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	temp = min(z1, y2)
	ans += temp * 2
	z1 = z1 - temp
	y2 = y2 - temp
	if z1 > 0:
		if z2 > z1:
			z2 = z2 - z1
			z1 = 0
		else:
			z1 = z1 - z2
			z2 = 0
	if z1 > 0:
		if x2 > z1:
			x2 = x2 - z1
			z1 = 0
		else:
			z1 = z1 - x2
			x2 = 0
	if x2 == 0 and y2 == 0 and (z2 == 0):
		print(ans)
		continue
	if z2 > 0:
		if x1 > z2:
			x1 = x1 - z2
			z2 = 0
		else:
			z2 = z2 - x1
			x1 = 0
	if z2 == 0:
		print(ans)
		continue
	if y1 > 0:
		if x2 > y1:
			x2 = x2 - y1
			y1 = 0
		else:
			y1 = y1 - x2
			x2 = 0
	if y1 == 0:
		print(ans)
		continue
	if y1 > y2:
		y1 = y1 - y2
		y2 = 0
	else:
		y2 = y2 - y1
		y1 = 0
	if y1 == 0:
		print(ans)
		continue
	ans -= z2 * 2
	print(ans)


import math
import heapq
import bisect
import collections
import fractions
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	m = min(a[2], b[1])
	ans += m * 2
	a[2] -= m
	b[1] -= m
	m = min(a[2], b[2])
	b[2] -= m
	for i in range(1, -1, -1):
		m = min(a[1], b[i])
		a[1] -= m
		b[i] -= m
	ans -= min(a[1], b[2]) * 2
	print(ans)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	(x1, y1, z1) = get_tuple()
	(x2, y2, z2) = get_tuple()
	if x1 >= x2 + z2:
		ans = z1 * 2
	elif x1 >= z2:
		ans = min(y2, z1) * 2
	else:
		z2 -= x1
		if z2 >= z1:
			z2 -= z1
			ans = -z2 * 2
		else:
			z1 -= z2
			ans = min(z1, y2) * 2
	print(ans)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


def solve():
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	s = 0
	m = min(a0, b2)
	a0 -= m
	b2 -= m
	m = min(a1, b0)
	a1 -= m
	b0 -= m
	m = min(a2, b1)
	a2 -= m
	b1 -= m
	s += 2 * m
	s -= 2 * min(a1, b2)
	print(s)
for __ in range(int(input())):
	solve()


def solve(arr1, arr2):
	ans = 2 * min(arr1[2], arr2[1])
	temp = max(0, min(arr1[2], arr2[1]))
	arr1[2] -= temp
	arr2[1] -= temp
	temp = max(0, min(arr1[2], arr2[2]))
	arr1[2] -= temp
	arr2[2] -= temp
	temp = max(0, min(arr1[2], arr2[0]))
	arr1[2] -= temp
	arr2[0] -= temp
	temp = max(0, min(arr1[0], arr2[2]))
	arr1[0] -= temp
	arr2[2] -= temp
	temp = max(0, min(arr1[0], arr2[1]))
	arr1[0] -= temp
	arr2[1] -= temp
	temp = max(0, min(arr1[0], arr2[0]))
	arr1[0] -= temp
	arr2[0] -= temp
	temp = max(0, min(arr1[1], arr2[1]))
	arr1[1] -= temp
	arr2[1] -= temp
	temp = max(0, min(arr1[1], arr2[0]))
	arr1[1] -= temp
	arr2[0] -= temp
	ans -= 2 * arr1[1]
	print(ans)
t = int(input())
for _ in range(t):
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	solve(arr1, arr2)


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


for t in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sm = 0
	two1 = min(z1, y2)
	sm += 2 * two1
	z1 -= two1
	y2 -= two1
	one0 = min(y1, x2)
	y1 -= one0
	x2 -= one0
	one1 = min(y1, y2)
	y1 -= one1
	y2 -= one1
	one2 = min(z2, y1)
	sm -= 2 * one2
	z2 -= one2
	y1 -= one2
	print(sm)


def calc(s1, s2):
	plus = min(s1[2], s2[1])
	s1[2] -= plus
	s2[1] -= plus
	minus = max(s2[2] - s1[0] - s1[2], 0)
	return (plus - minus) * 2

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def seq2str(seq):
	return ' '.join((str(item) for item in seq))
a = get_ints()
assert len(a) == 1
t = a[0]
for i in range(t):
	a = get_ints()
	assert len(a) == 3
	s1 = a
	a = get_ints()
	assert len(a) == 3
	s2 = a
	assert sum(s1) == sum(s2)
	res = calc(s1, s2)
	print(res)


import sys, math

def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		(zeroa, onea, twoa) = mii()
		(zerob, oneb, twob) = mii()
		ans = 0
		ans += min(twoa, oneb) * 2
		twoa -= min(twoa, oneb)
		oneb -= min(twoa, oneb)
		if twoa + zeroa >= twob:
			print(ans)
			continue
		else:
			twob -= twoa + zeroa
			ans -= twob * 2
			print(ans)
main()


for i in range(int(input())):
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	w = min(arr1[2], arr2[1])
	arr1[2] = arr1[2] - w if arr2[1] < arr1[2] else 0
	s = arr1[0] + arr1[2]
	w1 = arr2[2] - s if arr2[2] > s else 0
	print(w * 2 + w1 * -2)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	(x0, x1, x2) = IP()
	(y0, y1, y2) = IP()
	score = min(x2, y1)
	x2 -= score
	y1 -= score
	avail = y0 + y1
	x1 = max(0, x1 - avail)
	lose = min(y2, x1)
	print((score - lose) * 2)
	return
t = II()
for i in range(t):
	solve()


import math
T = int(input())
for i in range(T):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	n = x1 + y1 + z1
	a = min(z1, y2)
	b = max(y2 + z2 - z1 - x1 - (y2 - a), 0)
	print(a * 2 - 2 * b)


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap
from itertools import product

def slv(XYZ1, XYZ2):
	ans = 0
	A = {0: XYZ1[0], 1: XYZ1[1], 2: XYZ1[2]}
	B = {0: XYZ2[0], 1: XYZ2[1], 2: XYZ2[2]}
	k = []
	for (i, j) in product(range(3), repeat=2):
		if i == j:
			k.append((0, i, j))
		elif i > j:
			k.append((i * j, i, j))
		else:
			k.append((-i * j, i, j))
	k.sort(reverse=True)
	for (v, i, j) in k:
		n = min(A[i], B[j])
		ans += v * n
		A[i] -= n
		B[j] -= n
	return ans

def main():
	for _ in range(read_int()):
		XYZ1 = read_int_n()
		XYZ2 = read_int_n()
		print(slv(XYZ1, XYZ2))
main()


for i in range(int(input())):
	(x1, y1, z1) = list(map(int, input().split()))
	(x2, y2, z2) = list(map(int, input().split()))
	pos = min(z1, y2)
	y2 = max(0, y2 - pos)
	z1 = max(0, z1 - pos)
	neg = x1 + z1 - z2
	if neg > 0:
		neg = 0
	else:
		neg = -neg
	print(2 * (pos - neg))


T = int(input())
while T != 0:
	(a0, a1, a2) = map(int, input().strip().split())
	(b0, b1, b2) = map(int, input().strip().split())
	ans = 0
	if a2 <= b1:
		ans += 2 * a2
		b1 -= a2
		a2 = 0
		if b2 > a0:
			ans -= (b2 - a0) * 2
	else:
		ans += 2 * b1
		a2 -= b1
		if b2 > a2 + a0:
			ans -= (b2 - a2 - a0) * 2
	print(ans)
	T -= 1


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	maximum = min(a[2], b[1])
	a[2] -= maximum
	b[1] -= maximum
	maximum *= 2
	if a[0] >= b[2]:
		print(maximum)
	else:
		b[2] -= a[0]
		if a[2] >= b[2]:
			print(maximum)
		else:
			b[2] -= a[2]
			subs = min(b[2], a[1])
			subs *= 2
			print(maximum - subs)


for z in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	small = min(z1, y2)
	ans = 2 * small
	z1 -= small
	y2 -= small
	small = min(x1, z2)
	x1 -= small
	z2 -= small
	small = min(y1, x2)
	y1 -= small
	x2 -= small
	small = min(y1, y2)
	y1 -= small
	y2 -= small
	ans -= 2 * min(y1, z2)
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	a = l()
	b = l()
	m = min(a[-1], b[1])
	answer = m * 2
	a[-1] -= m
	b[1] -= m
	m = min(a[-1], b[-1])
	a[-1] -= m
	b[-1] -= m
	m = min(a[0], b[-1])
	a[0] -= m
	b[-1] -= m
	m = min(a[1], b[1])
	a[1] -= m
	b[1] -= m
	m = min(a[-1], b[0])
	a[-1] -= m
	b[0] -= m
	m = min(a[1], b[0])
	a[1] -= m
	b[0] -= m
	m = min(a[0], b[1])
	a[0] -= m
	b[1] -= m
	m = min(a[0], b[0])
	a[0] -= m
	b[0] -= m
	m = min(a[1], b[-1])
	answer -= 2 * m
	a[1] -= m
	b[-1] -= m
	out(answer)


def Input(Str):
	List = Str.split(' ')
	for i in range(len(List)):
		List[i] = int(List[i])
	return List

def Total(x1, y1, z1, x2, y2, z2):
	Positive = 2 * min(y2, z1)
	if y2 > z1:
		y2 = y2 - z1
		z1 = 0
	else:
		z1 = z1 - y2
		y2 = 0
	while z2 > 0 and (x1 > 0 or z1 > 0):
		if x1 > 0:
			if z2 > x1:
				z2 = z2 - x1
				x1 = 0
			else:
				x1 = x1 - z2
				z2 = 0
		if z1 > 0:
			if z2 > z1:
				z2 = z2 - z1
				z1 = 0
			else:
				z1 = z1 - z2
				z2 = 0
	Negative = 2 * min(z2, y1)
	return Positive - Negative
trials = int(input(''))
for i in range(trials):
	Str1 = input('')
	Str2 = input('')
	[x1, y1, z1] = Input(Str1)
	[x2, y2, z2] = Input(Str2)
	print(Total(x1, y1, z1, x2, y2, z2))


def sequence(a, b):
	max_c = min(a[2], b[1])
	if a[2] >= b[1]:
		if a[2] - b[1] + a[0] >= b[2]:
			return max_c * 2
		else:
			min_c = b[2] - (a[2] - b[1] + a[0])
			return 2 * max_c - 2 * min_c
	elif a[0] >= b[2]:
		return max_c * 2
	else:
		min_c = b[2] - a[0]
		return 2 * max_c - 2 * min_c
t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(sequence(a, b))


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum_ = 0
	p = min(z1, y2)
	sum_ += p * 2
	z1 -= p
	y2 -= p
	if z1 > 0:
		p = min(z1, z2)
		z1 -= p
		z2 -= p
	if z1 > 0:
		p = min(z1, x2)
		z1 -= p
		x2 -= p
	if z2 > 0:
		p = min(z2, x1)
		z2 -= p
		x1 -= p
	if z2 > 0:
		p = min(z2, y1)
		sum_ -= p * 2
		z2 -= p
		y1 -= p
	print(sum_)


def calc(x1, y1, z1, x2, y2, z2):
	s = 0
	if y2 >= z1:
		s += 2 * z1
		if z2 > x1:
			s = s - 2 * (z2 - x1)
	else:
		s += 2 * y2
		if z2 > z1 - y2 + x1:
			s = s - 2 * (z2 - (z1 - y2) - x1)
	print(s)
	return
t = input()
for test in range(int(t)):
	a = input()
	a = a.split()
	a_list = [int(i) for i in a]
	x1 = a_list[0]
	y1 = a_list[1]
	z1 = a_list[2]
	a = input()
	a = a.split()
	a_list = [int(i) for i in a]
	x2 = a_list[0]
	y2 = a_list[1]
	z2 = a_list[2]
	calc(x1, y1, z1, x2, y2, z2)


T = int(input())
for t in range(T):
	i = input().split()
	x1 = int(i[0])
	y1 = int(i[1])
	z1 = int(i[2])
	i = input().split()
	x2 = int(i[0])
	y2 = int(i[1])
	z2 = int(i[2])
	sum = 0
	a = min(x1, z2)
	x1 -= a
	z2 -= a
	a = min(z1, y2)
	z1 -= a
	y2 -= a
	sum += a * 2
	a = min(z1, z2)
	z1 -= a
	z2 -= a
	sum -= z2 * 2
	print(sum)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(x1, y1, z1) = mi()
	(x2, y2, z2) = mi()
	c = 0
	c = 2 * min(z1, y2)
	p = min(z1, y2)
	(z1, y2) = (z1 - p, y2 - p)
	q = min(z1, x2)
	if z2 >= x1 + z1:
		c -= 2 * (z2 - x1 - z1)
	print(c)


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)))


t = int(input())

def minf(a, b):
	if a > b:
		return b
	else:
		return a
for i in range(0, t):
	(x1, y1, z1) = list(map(int, input().rstrip().split()))
	(x2, y2, z2) = list(map(int, input().rstrip().split()))
	fsum = 0
	v = minf(z1, y2)
	fsum += 2 * v
	z1 -= v
	y2 -= v
	v = minf(z1, z2)
	z1 -= v
	z2 -= v
	v = minf(x1, z2)
	x1 -= v
	z2 -= v
	v = minf(y1, y2)
	y1 -= v
	y2 -= v
	v = minf(y1, x2)
	y1 -= v
	x2 -= v
	v = minf(y1, z2)
	y1 -= v
	z2 -= v
	fsum -= 2 * v
	print(fsum)


for _ in range(int(input())):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = a[:]
	d = b[:]
	(a1, a2, a3) = a
	(b1, b2, b3) = b
	ans = 0
	k = min(a3, b2)
	ans += 2 * k
	a3 -= k
	b2 -= k
	k = min(a1 + a3, b3)
	ans -= 2 * (b3 - k)
	print(ans)


def findans(d, d1):
	if d[0] > 0:
		a = min(d[0], d1[2])
		d[0] = d[0] - a
		d1[2] = d1[2] - a
		if d[0] > 0:
			a = min(d[0], d1[0])
			d[0] = d[0] - a
			d1[0] -= a
		if d[0] > 0:
			a = min(d[0], d1[1])
			d[0] = d[0] - a
			d1[1] -= a
		if d[0] > 0:
			return 0
	if d1[0] > 0:
		b = min(d1[0], d[1])
		d1[0] = d1[0] - b
		d[1] -= b
		if d1[0] > 0:
			b = min(d1[0], d[2])
			d1[0] = d1[0] - b
			d[2] -= b
		if d1[0] > 0:
			return 0
	ans = 0
	a = min(d[2], d1[1])
	ans = ans + 2 * 1 * a
	b = min(d1[2], d[1])
	ans = ans - 2 * 1 * b
	return ans
n = int(input())
for i in range(n):
	d = {}
	d1 = {}
	(zero, one, two) = map(int, input().split())
	(zero1, one1, two1) = map(int, input().split())
	d[0] = zero
	d[1] = one
	d[2] = two
	d1[0] = zero1
	d1[1] = one1
	d1[2] = two1
	print(findans(d, d1))


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


import math

def solve():
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	small = min(z1, y2)
	ans = 2 * small
	z1 -= small
	y2 -= small
	small = min(x1, z2)
	x1 -= small
	z2 -= small
	small = min(y1, x2)
	y1 -= small
	x2 -= small
	small = min(y1, y2)
	y1 -= small
	y2 -= small
	ans -= 2 * min(y1, z2)
	print(ans)
for z in range(int(input())):
	solve()


for _ in range(int(input())):
	(x_1, y_1, z_1) = map(int, input().split())
	(x_2, y_2, z_2) = map(int, input().split())
	s = 0
	if z_1 > 0 and z_1 >= y_2:
		s += y_2 * 2
		z_1 -= y_2
		y_2 = 0
	elif y_2 > z_1 > 0:
		s += z_1 * 2
		y_2 -= z_1
		z_1 = 0
	if z_2 > 0 and z_2 >= x_1:
		z_2 -= x_1
		x_1 = 0
	elif x_1 > z_2 > 0:
		x_1 -= z_2
		z_2 = 0
	if z_2 > z_1 >= 0:
		z_2 -= z_1
		s -= z_2 * 2
	print(s)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split(' ')))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(x, y, z) = map(int, input().split(' '))
	(a, b, c) = map(int, input().split(' '))
	ans = 0
	v = min(x, c)
	x -= v
	c -= v
	k = min(y, a)
	y -= k
	a -= k
	last = min(z, b)
	b -= last
	z -= last
	ans += 2 * last
	ans -= 2 * min(y, c)
	print(ans)


for t in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = 0
	if z1 >= y2:
		c += y2 * 2
		z1 = z1 - y2
	else:
		c += z1 * 2
		z1 = 0
	if z2 >= x1:
		z2 = z2 - x1
	else:
		z2 = 0
	if z2 != 0:
		if z1 != 0:
			if z2 >= z1:
				z2 -= z1
			else:
				z2 = 0
		if y1 != 0 and z2 != 0:
			if z2 >= y1:
				c -= y1 * 2
			else:
				c -= z2 * 2
	print(c)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(A, B, C) = map(int, input().split())
	kaamKBande = min(c, B)
	ans = kaamKBande * 2
	c -= kaamKBande
	B -= kaamKBande
	bekarLog = min(c + a, C)
	C -= bekarLog
	if C:
		ans -= C * 2
	print(ans)


t = int(input())
for i in range(t):
	sum1 = 0
	(x1, y1, z1) = input().split()
	x1 = int(x1)
	y1 = int(y1)
	z1 = int(z1)
	(x2, y2, z2) = input().split()
	x2 = int(x2)
	y2 = int(y2)
	z2 = int(z2)
	if z1 >= y2:
		sum1 = sum1 + 2 * y2
		z1 = z1 - y2
		y2 = 0
		z2 = z2 - z1
	else:
		sum1 = sum1 + 2 * z1
		y2 = y2 - z1
		z1 = 0
	if z2 > x1:
		z2 = z2 - x1
	else:
		z2 = 0
	if z2 >= y1:
		sum1 = sum1 - 2 * y1
	else:
		sum1 = sum1 - 2 * z2
	print(sum1)


T = int(input())
while T:
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	x = min(z1, y2)
	s = 2 * x
	z1 -= x
	y2 -= x
	y = min(y1, y2)
	y1 -= y
	y2 -= y
	y = min(y1, x2)
	y1 -= y
	x2 -= y
	z = min(z1, z2)
	z1 -= z
	z2 -= z
	z = min(z2, x1)
	z2 -= z
	x1 -= z
	s -= 2 * min(y1, z2)
	print(s)
	T -= 1


from sys import stdin, stdout
import math
input = stdin.readline
print = stdout.write
n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	suma = 0
	mina = min(c, y)
	suma += 2 * mina
	c -= mina
	y -= mina
	if c > 0:
		mina = min(c, z)
		z -= mina
	mina = min(a, z)
	z -= mina
	suma -= 2 * z
	print(str(suma) + '\n')


from sys import stdin, stdout
input = stdin.readline

def geti():
	return map(int, input().strip().split())

def getl():
	return list(map(int, input().strip().split()))

def gets():
	return input('')

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	for _ in range(geta()):
		(a0, a1, a2) = geti()
		(b0, b1, b2) = geti()
		left = min(a2, b1)
		ans = left * 2
		a2 -= left
		b1 -= left
		a1 -= b1
		b2 -= a2
		if b2 <= 0 or a1 <= 0:
			print(ans)
			continue
		a1 -= b0
		if a1 > 0:
			ans -= min(a1, b2) * 2
		print(ans)
solve()


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	(z1, o1, t1) = vars()
	(z2, o2, t2) = vars()
	ans = 0
	ans += 2 * min(t1, o2)
	temp = min(t1, o2)
	t1 -= temp
	o2 -= temp
	temp = min(z1, t2)
	t2 -= temp
	z1 -= temp
	temp = min(o1, z2)
	o1 -= temp
	z2 -= temp
	ans -= 2 * min(o1, t2)
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	main()


for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans1 = 2 * min(z1, y2)
	z = z1 - min(z1, y2)
	y = y2 - min(z1, y2)
	z2 = max(0, z2 - z - x1)
	y1 = max(0, y1 - y - x2)
	ans2 = 2 * min(z2, y1)
	print(ans1 - ans2)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	m = min(x1, z2)
	x1 -= m
	z2 -= m
	m = min(y1, x2)
	y1 -= m
	x2 -= m
	ans += min(z1, y2) * 2
	m = min(z1, y2)
	z1 -= m
	y2 -= m
	ans -= min(z2, y1) * 2
	print(ans)


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())

def inp():
	return int(input())

def st1():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	(x1, y1, z1) = ma()
	(x2, y2, z2) = ma()
	f1 = min(z1, y2) * 2
	if z2 <= z1 - f1 // 2 + x1:
		print(f1)
		continue
	re = z2 - (z1 - f1 // 2 + x1)
	print(f1 - max(0, re) * 2)


n = int(input())
o = []
for i in range(n):
	m = 0
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	if a[2] <= b[1]:
		m += 2 * a[2]
		b[1] -= a[2]
		a[2] = 0
	else:
		m += 2 * b[1]
		a[2] -= b[1]
		b[1] = 0
	if a[2] <= b[2]:
		b[2] -= a[2]
		a[2] = 0
	else:
		a[2] -= b[2]
		b[2] = 0
	if a[2] <= b[0]:
		b[0] -= a[2]
		a[2] = 0
	else:
		a[2] -= b[0]
		b[0] = 0
	if a[0] <= b[2]:
		b[2] -= a[0]
		a[0] = 0
	else:
		a[0] -= b[2]
		b[2] = 0
	if a[0] <= b[1]:
		b[1] -= a[0]
		a[0] = 0
	else:
		a[0] -= b[1]
		b[1] = 0
	if a[0] <= b[0]:
		b[0] -= a[0]
		a[0] = 0
	else:
		a[0] -= b[0]
		b[0] = 0
	if a[1] <= b[2]:
		m -= 2 * a[1]
		b[2] -= a[1]
		a[1] = 0
	else:
		m -= 2 * b[2]
		a[1] -= b[2]
		b[2] = 0
	if a[1] <= b[1]:
		b[1] -= a[1]
		a[1] = 0
	else:
		a[1] -= b[1]
		b[1] = 0
	if a[1] <= b[0]:
		b[0] -= a[1]
		a[1] = 0
	else:
		a[1] -= b[0]
		b[0] = 0
	o.append(m)
for i in o:
	print(i)


t = int(input())
for i in range(t):
	string1 = input()
	string2 = input()
	string1 = [int(element) for element in string1.split()]
	string2 = [int(element) for element in string2.split()]
	add = 0
	if string1[2] >= string2[1]:
		string1[2] -= string2[1]
		add += 2 * string2[1]
	else:
		add += 2 * string1[2]
		string1[2] = 0
	if string1[2] + string1[0] <= string2[2]:
		add -= 2 * (string2[2] - string1[2] - string1[0])
	print(add)


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')

def List():
	return list(map(int, input().split()))

def Num():
	return int(input())
for _ in range(Num()):
	(a, b, c) = List()
	(x, y, z) = List()
	ans = 0
	ans += min(c, y) * 2
	minn = min(c, y)
	c -= minn
	y -= minn
	if x + y < b:
		b -= x + y
	else:
		b = 0
	ans -= min(b, z) * 2
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	f = 0
	a1 = min(a, z)
	a -= a1
	z -= a1
	a1 = min(c, y)
	f += 2 * a1
	c -= a1
	y -= a1
	if z == 0 and y == 0:
		print(f)
	elif z == 0 and c == 0:
		print(f)
	elif a == 0 and c == 0:
		f -= 2 * z
		print(f)
	elif a == 0 and y == 0:
		a1 = min(z, c)
		z -= a1
		c -= a1
		if c:
			print(f)
		else:
			f -= 2 * z
			print(f)
	else:
		print(f)


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)


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(a, b, c) = R()
	(x, y, z) = R()
	if z > a + c:
		z -= a + c
		print(-2 * min(b, z))
	else:
		c -= max(0, z - a)
		print(2 * min(c, y))


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	(x1, y1, z1) = get_int()
	(x2, y2, z2) = get_int()
	tot = 0
	if z2 > x1:
		z2 -= x1
		x1 = 0
		if z2 > z1:
			z2 -= z1
			z1 = 0
			if z2 > y1:
				z2 -= y1
				tot -= y1 * 2
				y1 = 0
			else:
				tot -= z2 * 2
				y1 -= z2
				z2 = 0
		else:
			z1 -= z2
			z2 = 0
	if z1 > y2 and y2 != 0:
		tot += y2 * 2
		z1 -= y2
		y2 = 0
	elif y2 != 0:
		tot += z1 * 2
		y2 -= z1
		z1 = 0
	print(tot)


tc = int(input())
while tc > 0:
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 2 * min(a2, b1)
	if a0 < b2:
		diff = 2 * min(a1, b2 - a0 - max(0, a2 - b1))
		ans -= max(0, diff)
	print(ans)
	tc -= 1


try:
	t = int(input())
	for _ in range(t):
		(x1, y1, z1) = map(int, input().split())
		(x2, y2, z2) = map(int, input().split())
		to = min(z1, y2)
		z1 -= to
		y2 -= to
		tt = min(z1, z2)
		z1 -= tt
		z2 -= tt
		tz = min(z1, x2)
		z1 -= tz
		x2 -= tz
		oo = min(y1, y2)
		y1 -= oo
		y2 -= oo
		oz = min(y1, x2)
		y1 -= oz
		x2 -= oz
		ot = min(y1, z2)
		y1 -= ot
		z2 -= ot
		print(to * 2 - ot * 2)
except:
	pass


for vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv in range(int(input())):
	(xxxxxxxxxxxxxxxxxxxxxxxxcxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxdxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxexxxxxxxxxxxxxxxxx) = map(int, input().split())
	(xxxxxxxxxxxxxxxxxxxxxxxxbxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxaxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxoxxxxxxxxxxxxxxxxx) = map(int, input().split())
	xxxxxxxxxxxxxxxxxxxxxxxxmxxxxxxxxxxxxxxxxx = 2 * min(xxxxxxxxxxxxxxxxxxxxxxxxexxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxaxxxxxxxxxxxxxxxxx)
	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxu = min(xxxxxxxxxxxxxxxxxxxxxxxxexxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxaxxxxxxxxxxxxxxxxx)
	xxxxxxxxxxxxxxxxxxxxxxxxexxxxxxxxxxxxxxxxx -= xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxu
	xxxxxxxxxxxxxxxxxxxxxxxxaxxxxxxxxxxxxxxxxx -= xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxu
	xxxxxxxxxxxxxxxxxxxxxxxxmxxxxxxxxxxxxxxxxx -= 2 * min(max(0, xxxxxxxxxxxxxxxxxxxxxxxxdxxxxxxxxxxxxxxxxx - (xxxxxxxxxxxxxxxxxxxxxxxxbxxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxxxxxxxxaxxxxxxxxxxxxxxxxx)), max(0, xxxxxxxxxxxxxxxxxxxxxxxxoxxxxxxxxxxxxxxxxx - (xxxxxxxxxxxxxxxxxxxxxxxxcxxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxxxxxxxxexxxxxxxxxxxxxxxxx)))
	print(xxxxxxxxxxxxxxxxxxxxxxxxmxxxxxxxxxxxxxxxxx)


import math
t = int(input())
for q in range(t):
	(x1, y1, z1) = [int(i) for i in input().split()]
	(x2, y2, z2) = [int(i) for i in input().split()]
	r = max(z1 - y2, 0)
	r1 = min(x1 + r - z2, 0)
	r2 = min(z1, y2)
	print(2 * (r1 + r2))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	ans = 0
	(x0, x1, x2) = map(int, input().split())
	(y0, y1, y2) = map(int, input().split())
	ans += min(x2, y1) * 2
	x2 -= min(x2, y1)
	y1 -= min(x2, y1)
	y2_take = max(0, y2 - x2 - x0)
	ans -= y2_take * 2
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c) = [int(k) for k in input().split()]
	(x, y, z) = [int(k) for k in input().split()]
	n = x + y + z
	q = min(c, y)
	q += min(n - b - q - z, 0)
	print(q * 2)


t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	minimum = min(z1, y2)
	sum += minimum * 2
	z1 -= minimum
	y2 -= minimum
	minimum = min(x1, z2)
	x1 -= minimum
	z2 -= minimum
	minimum = min(z2, z1)
	z2 -= minimum
	z1 -= minimum
	sum -= z2 * 2
	print(sum)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	a = [int(x) for x in inp().split()]
	b = [int(x) for x in inp().split()]
	x = min(a[2], b[1])
	a[2] -= x
	b[1] -= x
	ans = x * 2
	y = max(b[2] - a[0] - a[2], 0)
	ans -= y * 2
	print(ans)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
con = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

def main():
	T = int(input())
	for _ in range(T):
		(x1, y1, z1) = getlist()
		(x2, y2, z2) = getlist()
		N = sum([x1, y1, z1])
		ans = 0
		val = min(z1, y2)
		ans += 2 * val
		z1 -= val
		y2 -= val
		val = min(x1 + z1, z2)
		z2 -= val
		ans -= 2 * z2
		print(ans)
main()


for i in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	ans = 0
	p = min(z1, y2)
	ans += 2 * p
	z1 -= p
	y2 -= p
	p = min(x2, y1)
	x2 -= p
	y1 -= p
	p = min(z2, x1)
	z2 -= p
	x1 -= p
	if y1 > 0 and y2 > 0:
		p = min(y1, y2)
		y1 -= p
		y2 -= p
	if z2 != 0:
		p = min(z2, z1)
		z2 -= p
		z1 -= p
	if z2 != 0:
		p = min(z2, y1)
		ans -= 2 * p
	print(ans)


t = int(input())
out = []
for T in range(t):
	sum = 0
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	m = min(a, f)
	a -= m
	f -= m
	m = min(b, d)
	b -= m
	d -= m
	m = min(c, e)
	c -= m
	e -= m
	sum += 2 * m
	sum -= 2 * min(b, f)
	out.append(sum)
for i in out:
	print(i)


def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		print(mid)
		if mid * mid == number:
			ans = mid
			print('hi')
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	print(str(ans) + 'hhee')
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans
t = int(input())
for i in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	c = 0
	if z1 >= y2:
		c += 2 * y2
		z1 = z1 - y2
		if z2 >= z1 + x1:
			z2 = z2 - z1 - x1
			if z2 >= 0:
				c -= 2 * z2
	else:
		c += 2 * z1
		y2 = y2 - z1
		if y1 >= y2 + x2:
			y1 = y1 - y2 - x2
			if y1 >= 0:
				c -= 2 * y1
	print(c)


import math
t = int(input())
for _ in range(t):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	E = min(z1, y2)
	z1 -= E
	y2 -= E
	N = max(0, y1 - x2 - y2)
	E -= N
	print(E * 2)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(x1, y1, z1) = Read.list_int()
	(x2, y2, z2) = Read.list_int()
	m = min(z1, y2)
	z1 = z1 - m
	y2 = y2 - m
	res = m * 2
	m = min(z2, x1)
	z2 = z2 - m
	x1 = x1 - m
	m = min(z2, z1)
	z2 = z2 - m
	z1 = z1 - m
	m = min(z2, y1)
	z2 = z2 - m
	y1 = y1 - m
	res = res - m * 2
	print(res)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


import random

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	k = min(a[2], b[1])
	ans += k * 2
	a[2] -= k
	b[1] -= k
	k = min(a[2], b[2])
	a[2] -= k
	b[2] -= k
	k = min(a[2], b[0])
	a[2] -= k
	b[0] -= k
	k = min(a[0], b[2])
	a[0] -= k
	b[2] -= k
	k = min(a[0], b[0])
	a[0] -= k
	b[0] -= k
	k = min(a[0], b[1])
	a[0] -= k
	b[1] -= k
	k = min(a[1], b[0])
	a[1] -= k
	b[0] -= k
	k = min(a[1], b[1])
	a[1] -= k
	b[1] -= k
	k = min(a[1], b[2])
	ans -= 2 * k
	a[1] -= k
	b[2] -= k
	print(ans)


tc = int(input())
while tc > 0:
	tc -= 1
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	sum = 0
	tm = min(z1, y2)
	sum += tm * 2
	z1 = z1 - tm
	z2 = z2 - z1
	z2 = z2 - x1
	if z2 < 0:
		z2 = 0
	sum -= z2 * 2
	print(sum)


for t in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	out = 2 * min(a2, b1)
	a2 -= out // 2
	b1 -= out // 2
	val = min(a1, b0)
	a1 -= val
	b0 -= val
	val = min(a0, b2)
	b2 -= val
	a0 -= val
	if b2 > a0 + a2:
		out -= 2 * (b2 - a0 - a2)
	print(out)


for t in range(int(input())):
	(x1, y1, z1) = map(int, input().split())
	(x2, y2, z2) = map(int, input().split())
	p21 = min(z1, y2)
	z1 -= p21
	y2 -= p21
	p11 = min(y1, y2)
	y1 -= p11
	y2 -= p11
	p10 = min(y1, x2)
	y1 -= p10
	x2 -= p10
	print(2 * (p21 - min(y1, z2)))


n = int(input())
for i in range(n):
	(a1, b1, c1) = map(int, input().split(' '))
	(a2, b2, c2) = map(int, input().split(' '))
	result = 0
	if c1 <= b2:
		result += 2 * c1
		c1 -= c1
		b2 -= c1
	else:
		result += 2 * b2
		c1 -= b2
		b2 -= b2
	if c2 > a1 + c1:
		result -= (c2 - a1 - c1) * 2
	print(result)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(a, b, c) = num_input()
	(x, y, z) = num_input()
	score = 0
	score += min(c, y) * 2
	c -= min(y, c)
	z -= min(c, z)
	score -= max(z - a, 0) * 2
	print(score)
t = 1
t = int(input())
for _ in range(t):
	solve()


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(x, y, z) = R()
	n = x + y + z
	(u, v, w) = R()
	print(n - max(y + w, n - min(z, v)) << 1)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(x1, y1, z1) = list(map(int, stdin.readline().rstrip().split()))
	(x2, y2, z2) = list(map(int, stdin.readline().rstrip().split()))
	ans = 0
	ans += 2 * min(z1, y2)
	rem1 = y2 - min(z1, y2)
	y1 -= rem1 + x2
	if y1 <= 0:
		print(ans)
		continue
	else:
		print(ans - 2 * y1)


for _ in range(int(input())):
	(a0, a1, a2) = map(int, input().split())
	(b0, b1, b2) = map(int, input().split())
	ans = 2 * min(a2, b1)
	temp = min(a2, b1)
	a2 -= temp
	b1 -= temp
	temp = min(a1, b0)
	a1 -= temp
	b0 -= temp
	temp = min(a1, b1)
	a1 -= temp
	b1 -= temp
	temp = min(a1, b2)
	a1 -= temp
	b2 -= temp
	ans -= 2 * temp
	print(ans)