from decimal import *
import sys
rasp_final=""
c=int(input())
for i in range(0,c):
a,b,c=list(map(int,input().split()))
d,e,f=list(map(int,input().split()))
suma=0
minimul=min(c,e)
suma+=minimul*2
c-=minimul
e-=minimul
minimul=min(c,f)
c-=minimul
f-=minimul
minimul=min(a,f)
a-=minimul
f-=minimul
minimul=min(a,e)
a-=minimul
e-=minimul
minimul=min(a,d)
a-=minimul
d-=minimul
minimul=min(b,e)
b-=minimul
e-=minimul
minimul=min(b,d)
b-=minimul
d-=minimul
minimul=min(c,f)
c-=minimul
f-=minimul
suma+=-2*(min(f,b))
print(suma)
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void solve(){
ll x1 , y1 , z1 , x2 , y2 , z2 ;
cin >> x1 >> y1 >> z1 ;
cin >> x2 >> y2 >> z2 ;
ll answer = 0 ;
ll t = min(x1 , z2) ;
x1 -= t ;
z2 -= t;
t = min(z1,y2) ;
answer += (t * 2) ;
z1 -= t ;
y2 -= t ;
t = min(z1,z2) ;
z2 -= t ;
z1 -= t ;
answer -= (z2 * 2) ;
cout << answer << endl ;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
1110A - Parity | 1215B - The Number of Products |
604C - Alternative Thinking | 1204C - Anna Svyatoslav and Maps |
322A - Ciel and Dancing | 1689B - Mystic Permutation |
1711B - Party | 1702D - Not a Cheap String |
1714F - Build a Tree and That Is It | 1703F - Yet Another Problem About Pairs Satisfying an Inequality |
610A - Pasha and Stick | 1200A - Hotelier |
1091A - New Year and the Christmas Ornament | 1352B - Same Parity Summands |
1102A - Integer Sequence Dividing | 630B - Moore's Law |
1004A - Sonya and Hotels | 1680B - Robots |
1690A - Print a Pedestal (Codeforces logo) | 1295A - Display The Number |
1077A - Frog Jumping | 1714G - Path Prefixes |
1369C - RationalLee | 289B - Polo the Penguin and Matrix |
1716A - 2-3 Moves | 1670B - Dorms War |
1716B - Permutation Chain | 987A - Infinity Gauntlet |
1676G - White-Black Balanced Subtrees | 1716D - Chip Move |