#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;
ll fun(ll x,ll y,ll z,ll a,ll b,ll c)
{
    ll ans=0;
 	ans+=(min(z,b)*2);
 	ll v;
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(z,c);
    z-=v;
 	c-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=((y*c)*2);
 	return ans;
}
ll fun1(ll x,ll y,ll z,ll a,ll b,ll c)
{

ll ans=0;
    ll v;
    v=min(z,c);
    z-=v;
 	c-=v;
 	ans+=(min(z,b)*2);
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=((y*c)*2);
 	return ans;
}
int main()
{
	ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
   ll ans=max(fun(x,y,z,a,b,c),fun1(x,y,z,a,b,c));
   pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=0;
 	ans+=(min(z,b)*2);
 	ll v;
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(z,c);
    z-=v;
 	c-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=((y*c)*2);
 	pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=0;
 	ans+=min(z,b)*2;
 	z-=min(z,b);
 	b-=min(z,b);
    z-=min(z,c);
 	c-=min(z,c);
 	z-=min(z,a);
 	a-=min(z,a);
 	x-=min(x,c);
 	c-=min(x,c);
 	x-=min(x,b);
 	b-=min(x,b);
 	x-=min(x,a);
 	a-=min(x,a);
 	y-=min(y,a);
 	a-=min(y,a);
 	y-=min(y,b);
 	b-=min(y,b);
 	ans-=(y*c)*2;
 	pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=0;
 	ans+=min(z,b)*2;
 	ll v;
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(z,c);
    z-=v;
 	c-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=(y*c)*2;
 	pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=0;
 	ans+=(min(z,b)*2);
 	ll v;
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(z,c);
    z-=v;
 	c-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=((y)*2);
 	pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;
ll fun(ll x,ll y,ll z,ll a,ll b,ll c)
{
    ll ans=0;
 	ans+=(min(z,b)*2);
 	ll v;
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(z,c);
    z-=v;
 	c-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=((y*c)*2);
 	return ans;
}
ll fun1(ll x,ll y,ll z,ll a,ll b,ll c)
{

ll ans=0;
    ll v;
    v=min(z,c);
    z-=v;
 	c-=v;
 	v=min(y,b);
 	y-=v;
 	b-=v;
 	ans+=(min(z,b)*2);
 	v=min(z,b);
 	z-=v;
 	b-=v;
 	v=min(y,a);
 	y-=v;
 	a-=v;
 	v=min(z,a);
 	z-=v;
 	a-=v;
 	v=min(x,c);
 	x-=v;
 	c-=v;
 	v=min(x,b);
 	x-=v;
 	b-=v;
 	v=min(x,a);
 	x-=v;
 	a-=v;
 	ans-=((y*c)*2);
 	return ans;
}
int main()
{
	ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
   ll ans=max(fun(x,y,z,a,b,c),fun1(x,y,z,a,b,c));
   pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=0;
 	ans+=min(z,b)*2;
 	z-=min(z,b);
 	b-=min(z,b);
    z-=min(z,c);
 	c-=min(z,c);
 	y-=min(y,a);
 	a-=min(y,a);
 	y-=min(y,b);
 	b-=min(y,b);
 	z-=min(z,a);
 	a-=min(z,a);
 	x-=min(x,c);
 	c-=min(x,c);
 	x-=min(x,b);
 	b-=min(x,b);
 	x-=min(x,a);
 	a-=min(x,a);
 	ans-=(y*c)*2;
 	pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=0;
 	ans+=min(z,b)*2;
 	z-=min(z,b);
 	b-=min(z,b);
 	z-=min(z,c);
 	c-=min(z,c);
 	z-=min(z,a);
 	a-=min(z,a);
 	x-=min(x,c);
 	c-=min(x,c);
 	x-=min(x,b);
 	b-=min(x,b);
 	x-=min(x,a);
 	a-=min(x,a);
 	y-=min(y,a);
 	a-=min(y,a);
 	y-=min(y,b);
 	b-=min(y,b);
 	ans-=(y*c);
 	pf(ans),nw;
 }
}


#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>
#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

int main()
{
 ll t,x,y,z,a,b,c;
 sf(t);
 while(t--)
 {
 	sf(x),sf(y),sf(z);
 	sf(a),sf(b),sf(c);
 	ll ans=min(z,b)*2;
 	pf(ans),nw;
 }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        long long int ans=0;
        //if(y1<=x2) ans = 2*min(z1,y2);
        //else if(y1<=(x2+y2)) ans = 2*min(z1,y2-y1+x2);
        //else ans = -2*(y1-x2-y2);
        //cout<<ans<<endl;
        ans = -2*min(max(z2-x1,0)-z1,0) + 2*min(min(2*z1-max(z2-x1,0),0),y2);
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        long long int ans=0;
        //if(y1<=x2) ans = 2*min(z1,y2);
        //else if(y1<=(x2+y2)) ans = 2*min(z1,y2-y1+x2);
        //else ans = -2*(y1-x2-y2);
        //cout<<ans<<endl;
        ans = -2*max(max(z2-x1,0)-z1,0) + 2*min(min(2*z1-max(z2-x1,0),0),y2);
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        long long int ans=0;
        if(y1<=x2) ans = 2*min(z1,y2);
        else if(y1<=(x2+y2)) ans = 2*min(z1,y2-y1+x2);
        else ans = -2*(y1-x2-y2);
        cout<<ans<<endl;
       // ans = -2*min(max(z2-x1,0)-z1,0) + 2*min(min(2*z1-max(z2-x1,0),0),y2);
        //cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int m = min(x1,z2);
        x1-=m;
        z2-=m;
        int m2 = min(y1,x2);
        y1-=m2;
        x2-=m2;
        int m3 = min(y2,z1);
        z1-=m3;y2-=m3;
        long long int ans=0;
        ans+= 2*m3 - 2*(min(y1,z2));
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        long long int ans=0;
        if(y1<=x2) ans = 2*min(z1,y2);
        else if(y1<=(x2+y2)) ans = 2*min(z1,y2-y1+x2);
        else ans = -2*(y1-x2-y2);
        cout<<ans<<el;
       // ans = -2*min(max(z2-x1,0)-z1,0) + 2*min(min(2*z1-max(z2-x1,0),0),y2);
        //cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int a[n],b[n];
        int ans=0;
        for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int a[n],b[n];
        int ans=0;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        ans = 2*min(z1,y2) - 2*max(z2-x1-z1+y2,0);
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int m = min(x1,z2);
        x1-=m;
        z2-=z2-m;
        int m2 = min(y1,x2);
        y1-=m2;
        x2-=m2;
        int m3 = min(y2,z1);
        z1-=m3;y2-=m3;
        long long int ans=0;
        ans+= 2*m3 - 2*(min(y1,z2));
        cour<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int m = min(x1,z2);
        x1-=m;
        z2-=z2-m;
        int m2 = min(y1,x2);
        y1-=m2;
        x2-=m2;
        int m3 = min(y2,z1);
        z1-=m3;y2-=m3;
        long long int ans=0;
        ans+= 2*m3 - 2*(min(y1,z2));
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int a[n],b[n];
        int ans=0;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        ans = -2*min(max(z2-x1,0)-z1,0) + 2*min(min(2*z1-max(z2-x1,0),0),y2);
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        int a[n],b[n];
        int ans=0;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        ans = -2*min(max(z2-x1,0)-z1,0) + 2*min(z1-max(z2-x1,0),0);
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include<string>
#include<vector>
//#include <iostream>
//#include <math.h>
using namespace std;
long long int max(long long int a, long long int b)
{
    if(a>b)return a;
    else return b;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("../input.txt","r",stdin);
        freopen("../output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    while (t--)
    {
        int x1,y1,z1;
        cin>>x1>>y1>>z1;
        int x2,y2,z2;
        cin>>x2>>y2>>z2;
        int n = x1+y1+z1;
        /*for(int i=n-1;i>=0;i--)
        {
            if(z1>0){a[i]=2;z1--;}
            else if(y1>0){a[i]=1;y1--;}
            else a[i] = 0;
            if(y2>0){b[i]=1;y2--;}
            else if(x2>0){b[i]=0;x2--;}
            else b[i] = 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]>b[i])ans+= a[i]*b[i];
            else if(a[i]<b[i])ans-=a[i]*b[i];
            //ans+= a[i]>b[i]?a[i]*b[i]:(a[i]==b[i]?0:(-a[i]*b[i]));
        }*/
        long long int ans=0;
        //if(y1<=x2) ans = 2*min(z1,y2);
        //else if(y1<=(x2+y2)) ans = 2*min(z1,y2-y1+x2);
        //else ans = -2*(y1-x2-y2);
        //cout<<ans<<endl;
        ans = -2*max(max(z2-x1,0)-z1,y1) + 2*min(min(2*z1-max(z2-x1,0),0),y2);
        cout<<ans<<endl;
    }
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
    int T,a,b,c,d,e;
    for(cin>>T;T--;cout<<min(min(c,e),d+e-b)*2<<' ')cin>>a>>b>>c>>d>>e>>a;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lli long long int

void algo(){
    int vec1[3],vec2[3];

    for(int i=0;i<3;i++)
        cin>>vec1[i];

    for(int i=0;i<3;i++)
        cin>>vec2[i];

    int sum=0;
    if(vec2[2]>=vec1[0]){
        vec2[2]-=vec1[0];
        vec1[0]=0;
    }
    else{
        vec1[0]-=vec2[2];
        vec2[2]=0;
    }
    if(vec2[2]>=vec1[2]){
        vec2[2]-=vec1[2];
        vec1[2]=0;
    }
    else{
        vec1[2]-=vec2[2];
        vec2[2]=0;
    }
    sum+=min(vec2[1],vec1[2])*2;
    sum+=vec2[2]*(-2);
    cout<<sum<<endl;

    return;
}

int32_t  main(){
    //freopen("input.txt", "r", stdin);
    IOS
    lli  t;
    cin>>t;
    while(t--){
       algo();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

long long int max(long long int a,long long int b)
{
    return (a>b?a:b);
}
long long int min(long long int a,long long int b)
{
    return (a<b?a:b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;

        int k=0;
        long long int sum=0,sum1=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;

        z2=z2-(min(z1,y1));
        long long int diff=max(0,z2-x1);

        for(long long int i=0;i<min(diff,y1);i++)
        {
           sum-=2;
        }

        cout<<max(sum,sum1)<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

long long int max(long long int a,long long int b)
{
    return (a>b?a:b);
}
long long int min(long long int a,long long int b)
{
    return (a<b?a:b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;

        int k=0;
        long long int sum=0,sum1=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;

        z2=z2-(z1-(min(z1,y2)));
       // cout<<z2<<" ";
        long long int diff=max(0,z2-x1);

        for(long long int i=0;i<min(diff,y1);i++)
        {
           sum-=2;
        }

        cout<<sum<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

long long int max(long long int a,long long int b)
{
    return (a>b?a:b);
}
long long int min(long long int a,long long int b)
{
    return (a<b?a:b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;
        vector<int> vec1(n+1),vec2(n+1);
        int k=0;
        int sum=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;
       // cout<<sum<<" ";
        int diff=max(0,z2-x1);
        for(long long int i=0;i<min(diff,y1);i++)
       {
           sum-=2;
       }

        cout<<sum<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

long long int max(long long int a,long long int b)
{
    return (a>b?a:b);
}
long long int min(long long int a,long long int b)
{
    return (a<b?a:b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;

        int k=0;
        long long int sum=0,sum1=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;

        z2=z2-(z1-(min(z1,y2)));
       // cout<<z2<<" ";
        long long int diff=max(0,z2-x1);

        for(long long int i=0;i<min(diff,y1);i++)
        {
           sum-=2;
        }

        cout<<max(sum,sum1)<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;
        vector<int> vec1(n+1),vec2(n+1);
        int k=0;
        int sum=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;
       // cout<<sum<<" ";
        for(long long int i=0;i<min(z2-x1,y1);i++)
       {
           sum-=2;
       }

        cout<<sum<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;
        vector<int> vec1(n+1),vec2(n+1);
        int k=0;
        for(long long int i=0;i<x1;i++)
            vec1[k++]=0;
        for(long long int i=0;i<y1;i++)
            vec1[k++]=1;
        for(long long int i=0;i<z1;i++)
            vec1[k++]=2;

        k=0;
       long long int sum=0;
        for(long long int i=0;i<y2;i++)
            vec2[k++]=1;
         for(long long int i=0;i<x2;i++)
            vec2[k++]=0;
        for(long long int i=0;i<z2;i++)
            vec2[k++]=2;
        sort(vec1.rbegin(),vec1.rend());
       // sort(vec2.begin(),vec2.end());
        for(long long int i=0;i<k;i++)
        {
            if(vec1[i] > vec2[i])
                sum+=vec1[i] * vec2[i];
            else if(vec1[i] < vec2[i])
                sum-=vec1[i]* vec2[i];
        }
        cout<<sum<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

long long int max(long long int a,long long int b)
{
    return (a>b?a:b);
}
long long int min(long long int a,long long int b)
{
    return (a<b?a:b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;

        int k=0;
        long long int sum=0,sum1=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;

        long long int diff=max(0,z2-x1);

        for(long long int i=0;i<min(diff,y1);i++)
        {
           sum-=2;
        }

         for(long long int i=0;i<min(z2,y1);i++)
            sum1+=2;

        diff=max(0,z1-x2);

        for(long long int i=0;i<min(diff,y2);i++)
        {
           sum1-=2;
        }

        cout<<max(sum,sum1)<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

long long int max(long long int a,long long int b)
{
    return (a>b?a:b);
}
long long int min(long long int a,long long int b)
{
    return (a<b?a:b);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int x1,y1,z1,x2,y2,z2;
        cin>>x1>>y1>>z1;
        cin>>x2>>y2>>z2;
        int n=x1+y1+z1;
        vector<int> vec1(n+1),vec2(n+1);
        int k=0;
        int sum=0;
        for(long long int i=0;i<min(z1,y2);i++)
            sum+=2;
       // cout<<sum<<" ";
        int diff=max(0,z2-x1);
        for(long long int i=0;i<min(diff,y1);i++)
       {
           sum-=2;
       }

        cout<<max(sum,0)<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=a1-b0;
       cout<<2*minm - 2*dif*b2<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b2);
       cout<<2*minm<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       b2-=minm;
       int dif=max(0,b2-a0-a2);
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=max(0,a1-b0);
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=(b2-a0-a2);
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=max(0,b2-a0-a2);
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       a2-=minm;
       int dif=max(0,b2-a0-a2);
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=a1-b0;
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=a1-b0;
       cout<<2*minm - dif*b2<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
using namespace std;
ll max(ll a,ll b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
ll min(ll a,ll b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
ll fact[1000000];
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}
bool isvowel(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='u' || ch=='o')
    {
        return true;
    }
    return false;
}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
       int a0,a1,a2; cin>>a0>>a1>>a2;
       int b0,b1,b2; cin>>b0>>b1>>b2;
       int minm=min(a2,b1);
       int dif=max(0,a1-b0-b1);
       cout<<2*minm - 2*dif<<endl;

    }
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;z=0;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=x+z)
    cout<<sum<<endl;
    else
    {Z-=(x+z);
      if(Y+Z>=y) y=0; else y-=(Y+Z);

        sum=-(Z*2*y)+sum;
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y)>=0)
     {y-=Y;
       if(y-X>=0)
        y=y-X;
        else
        {X=X-y;y=0;}
     }
     else
     y=0;
     if(y>0)
     {
         if(y-z>0)
          y-=z;
          else
          y=0;
     }
        sum+=-(Z-x)*2*(y);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;z=0;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=x+z)
    cout<<sum<<endl;
    else
    {Z-=(x+z);
      if(Y+X=y) y=0; else y-=(Y+X);

        sum=-(Z*2*y)+sum;
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;z=0;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=x+z)
    cout<<sum<<endl;
    else
    {Z-=(x+z);
      if(Y+X==y) y=0; else y-=(Y+X);

        sum=-(Z*2*y)+sum;
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;z=0;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=(x+z))
    cout<<sum<<endl;
    else
    {Z-=(x+z);
      if(Y+X>=y) y=0; else y-=(Y+X);

        sum=-(Z*2*y)+sum;
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y)>=0)
     {y-=Y;
       if(y-X>=0)
        y=y-X;
        else
        {X=X-y;y=0;}
     }
     else
     y=0;
     if(y>0)
     {
         if(y-z>0)
          y-=z;
          y=0;
     }
        sum+=-(Z-x)*2*(y);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    else
    Y=0;

    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y-X)>0)
     y=(y-Y-X);
     else
     y=0;
        sum+=-(Z-x)*2*(y-Y-X);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y-X)>0)
     y=(y-Y-X);
     else
     y=0;
        sum+=-(Z-x)*2*(y-Y-X);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;z=0;
    }
    else
   {z=z-Y ;Y=0;}

    if(Z<=x+z)
    cout<<sum<<endl;
    else
    {Z-=x+z;
      if(Y+Z>=y) y=0; else y-=Y+Z;

        sum+=-(Z)*2*(y);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    else
    Y=0;

    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y-X)>0)
     y=(y-Y-X);
     else
     y=0;
        sum+=-(Z-x)*2*(y);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    else
    Y=0;

    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y)>=0)
     {y-=Y;
       if(y-X>=0)
        y=y-X;
        else
        {X=X-y;y=0;}
     }
     else
     y=0;
        sum+=-(Z-x)*2*(y);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int x,y,z;cin>>x>>y>>z;
    int X,Y,Z;cin>>X>>Y>>Z;long long int sum=0;
    sum=(z>=Y?2*Y:2*(z));
    if(z<Y)
    {
        Y=Y-z;
    }
    if(Z<=x)
    cout<<sum<<endl;
    else
    {if((y-Y-X)>0)
     y=(y-Y-X)
     else
     y=0;
        sum+=-(Z-x)*2*(y-Y-X);
        cout<<sum<<endl;
    }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - max(0LL, f - a - min(c, e)) * b * 2LL) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - max(0LL, f - a - (c - min(c, e))) * max(0LL, b - d - (e - min(c, e))) * 2LL) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - max(0LL, f - a - min(c, e)) * b) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - max(0LL, f - a - (c - min(c, e)) - d - (e - min(c, e))) * b * 2LL) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - min(max(0LL, f - a - (c - min(c, e))), max(0LL, b - d - (e - min(c, e)))) * 2LL) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - max(0LL, f - a - (c - min(c, e))) * b * 2LL) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		int a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2 * min(c, e) - max(0, f - a - min(c, e)) * b) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2LL * min(c, e) - max(0LL, f - a - min(c, e)) * b * 2) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);

	int T;
	cin >> T;
	while (T--) {
		unsigned long long a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		cout << (2ULL * min(c, e) - max(0ULL, f - a - min(c, e)) * b) << "\n";
	}
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : max(b[2] - a[0] - a[2], 0) * -2 ) << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        cout << max(min(a[2], b[1]), min(b[2], a[1])) * 2 << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : min(a[2], b[1]) * 2 - max(b[2] - a[0] - a[2], 0) * -2 ) << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;
/// END NO SAD
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        int s = min(a[2], b[1]);
        a[2] -= s;
        b[1] -= s;
        a[0] += a[2];
        int sub = min(b[2], a[0]); /// min(b[2], a[0] + a[2]) ||||  2, 3
        a[0] -= sub;
        b[2] -= sub;
        int lose = min(b[2], a[1]);
        cout << (s - lose) * 2 << ee;
        //cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : min(a[2], b[1]) * 2 - max(0, b[2] - a[0] - a[2])* -2 ) << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : max(b[2] - a[0] - a[1], 0) * (-2)) << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        int ans = min(a[2], b[1]) * 2;
        if(a[2] >= b[2]){
            cout << ans << ee;
            continue;
        }
        a[0] += a[1];
        a[1] = 0;
        int g = min(a[2], b[1]);
        cout << ans + max(0, b[2] - a[0] - (a[2] - g)) * -2;
        //cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : min(a[2], b[1]) * 2 - max(0, b[2] - a[0] - a[2])* -2 ) << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        int ans = min(a[2], b[1]) * 2;
        if(a[2] >= b[2]){
            cout << ans << ee;
            continue;
        }
        a[0] += a[1];
        a[1] = 0;
        int g = min(a[2], b[1]);
        cout << ans + max(0, b[2] - a[0] - (a[2] - g)) * -2 << ee;
        //cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : min(a[2], b[1]) * 2 - max(0, b[2] - a[0] - a[2])* -2 ) << ee;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define out(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " ";
#define pb push_back
#define sz(x) (int)x.size()
#define ee "\n"
#define ff first
#define ss second

using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        vector<int> a(3), b(3);
        for(auto &it : a) cin >> it;
        for(auto &it : b) cin >> it;
        int ans = min(a[2], b[1]) * 2;
        if(a[2] >= b[2]){
            cout << ans << ee;
            continue;
        }
        int g = min(a[2], b[1]);
        cout << ans + max(0, b[2] - a[0] - (a[2] - g)) * -2 << ee;
        //cout << (a[2] >= b[2] ? min(a[2], b[1]) * 2 : min(a[2], b[1]) * 2 - max(0, b[2] - a[0] - a[2])* -2 ) << ee;
    }
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define endl        '\n'
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n,i;
        cin>>n;
        int arr[n];int ans=0;
                fo(i,0,n)
        {
            cin>>arr[i];
        }
        if(n==1){
        cout<<"YES\n";continue;}

        fo(i,0,n-1)
        {
            ans=ans+(arr[i]-arr[i+1]);
        }
        // cout<<ans;
        if(ans<=0)
        cout<<"YES\n";
        else
        cout<<"NO\n";
    }

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define endl        '\n'
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int a0,a1,a2,b0,b1,b2;
        cin>>a0>>a1>>a2>>b0>>b1>>b2;
        int ans;
        if(a2<=b1)
        {
            ans=2*a2;
            if(a0+b1-a2<b2)
            {
                ans-=((b2-(a0+b1-a2))*2);
            }
       }

        else{
        ans=(b1)*2;
        if(b2>(a0+a2-b1))
        {
            ans-=((b2-(a0+a2-b1))*2);
        }}
        cout<<(ans)<<endl;
    }

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define endl        '\n'
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int a0,a1,a2,b0,b1,b2;
        cin>>a0>>a1>>a2>>b0>>b1>>b2;
        if(a2<b1)
        cout<<2*a2<<endl;
        else
        cout<<(b1)*2<<endl;
    }

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define endl        '\n'
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int a0,a1,a2,b0,b1,b2;
        cin>>a0>>a1>>a2>>b0>>b1>>b2;
        int temp,ans=0;
        if(a2>0 && b1>0)
        {
            int temp=min(a2,b1);
            ans+=temp*2;
            a2-=temp;
            b1-=temp;
        }
        temp=min(a1,b1);
        a1-=temp;
        b1-=temp;
        temp=min(a2,b2);

        a2-=temp;
        b2-=temp;
        temp=min(a1,b0);
        a1-=temp;
        b0-=temp;
        temp=min(a1,b2);
        ans-=temp*2;
        cout<<ans<<endl;

    }

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define endl        '\n'
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int a0,a1,a2,b0,b1,b2;
        cin>>a0>>a1>>a2>>b0>>b1>>b2;
        int ans;
        if(a2<=b1)
        {
            ans=2*a2;
            if(a0<b2)
            {
                ans-=((a0-b2)*2);
            }
       }

        else{
        ans=(b1)*2;
        if(b2>(a0+a2-b1))
        {
            ans-=((b2>(a0+a2-b1))*2);
        }}
        cout<<abs(ans)<<endl;
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define INF 1e9
#define ll long long
#define ull unsigned long long

int t,n,m;
ll l,h;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    while(t--){
        cin >> n>> m;
        l = h = m;
        int sec,tl,th;
        int cur=0;
        int i;
        for(i=0;i<n;i++){
            cin >> sec >> tl>>th;
            int dist = sec-cur;
            l-=dist;
            h+=dist;

            if(l<-INF)
                l=INF;
            if(h>INF)
                h=INF;

            cur = sec;
            if(th<l || tl>h){
                cout <<"NO\n"; break;
            }

            if(l<tl)
                l=tl;
            if(h>th)
                h=th;

        }
        if(i==n){
            cout <<"YES\n";
        }
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define INF 1e9
#define ll long long
#define ull unsigned long long

int t,n,m;
ll l,h;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    while(t--){
        cin >> n>> m;
        l = h = m;
        int sec,tl,th;
        int cur=0;
        int i;
        for(i=0;i<n;i++){
            cin >> sec >> tl>>th;
            int dist = sec-cur;
            l-=dist;
            h+=dist;

            if(l<-INF)
                l=-INF;
            if(h>INF)
                h=INF;

            cur = sec;
            if(th<l || tl>h){
                cout <<"NO\n"; break;
            }

            if(l<tl)
                l=tl;
            if(h>th)
                h=th;

        }
        if(i==n){
            cout <<"YES\n";
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <utility>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

#define INF 1e9
#define ll long long

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int q;
	cin >> q;
	while(q--){
		int n,m;
		ll rl,rh;
		ll t,l,h;
		cin >> n >> m;
		rl = rh = m;
		int i;
		int cur_time =0;
		for(i=0;i<n;i++){
			cin >> t >> l >> h;
			rl -= t-cur_time; rh += t-cur_time;
			cur_time = t;

			if(-1*rl>INF){
				rl=INF;
				rl*=-1;
			}
			if(rh >INF)
				rh =INF;

			// if(rl < l){
			// 	if(h<rh){
			// 		rl=l;
			// 		rh=h;
			// 	}
			// 	else if(rh< l){
			// 		cout << "NO\n";
			// 		break;
			// 	}
			// }else if(rl <= h){
			// 	if(h<rh)
			// 		rh =h;
			// }
			// else{
			// 	cout << "NO\n";
			// 	break;
			// }

			if(rh<l || h < rl){
				cout << "NO\n";
				break;
			}else{
				if(rl<l){
					rl=l;
				}
				if(h<rh){
					rh=h;
				}
			}

			//cout << "rl = "<<rl <<", rh = "<<rh <<'\n';
		}
		if(i==n)
			cout <<"YES\n";
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define INF 1e9
#define ll long long
#define ull unsigned long long

int t,n,m;
ll l,h;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    while(t--){
        cin >> n>> m;
        l = h = m;
        int sec,tl,th;
        int cur=0;
        int i;
        for(i=0;i<n;i++){
            cin >> sec >> tl>>th;
            int dist = sec-cur;
            l-=dist;
            h+=dist;

            // if(l<-INF)
            //     l=-INF;
            // if(h>INF)
            //     h=INF;

            cur = sec;
            if(th<l || tl>h){
                cout <<"NO\n"; break;
            }

            if(l<tl)
                l=tl;
            if(h>th)
                h=th;

        }
        if(i==n){
            cout <<"YES\n";
        }
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define INF 1e9
#define ll long long
#define ull unsigned long long

int t,n,m,l,h;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    while(t--){
        cin >> n>> m;
        l = h = m;
        int sec,tl,th;
        int cur=0;
        int i;
        for(i=0;i<n;i++){
            cin >> sec >> tl>>th;
            int dist = sec-cur;
            l-=dist;
            h+=dist;
            cur = sec;
            if(th<l || tl>h){
                cout <<"NO\n"; break;
            }

            if(l<tl)
                l=tl;
            if(h>th)
                h=th;
        }
        if(i==n){
            cout <<"YES\n";
        }
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define INF 1e9
#define ll long long
#define ull unsigned long long

int t,n,m;
ll l,h;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> t;
    while(t--){
        cin >> n>> m;
        l = h = m;
        int minute,tl,th;
        int cur=0;
        int i;
        bool isOK=true;
        for(i=0;i<n;i++){
            cin >> minute >> tl>>th;
            int dist = minute-cur;
            l-=dist;
            h+=dist;

            if(l<-INF)
                l=-INF;
            if(h>INF)
                h=INF;

            cur = minute;
            if(th<l || tl>h){
                isOK=false;
            }

            if(l<tl)
                l=tl;
            if(h>th)
                h=th;

        }
        if(isOK){
            cout <<"YES\n";
        }else{
            cout <<"NO\n";
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1e5 + 5;
int n;

int solve(){
	int m;
	cin>>n>>m;
	int l=m, r=m;
	bool ok = true;
	int ptime = 0;
	for(int i=0; i<n; i++) {
		int time, low, up;
		cin>>time>>low>>up;
		int d = time - ptime;
		l -= d;
		r += d;
		if((l < low && r < low) || (l > up && r > up)) {
			ok = false;
			break;
		}
		else{
			l = max(l, low);
			r = min(r, up);
		}
		ptime = time;
	}
	if(ok) {
		cout<<"yes\n";
	}
	else{
		cout<<"no\n";
	}
}

int main(){
	fast;
	ll testcase;
	cin>>testcase;
	 // testcase = 1;
	while(testcase--) {
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1e5 + 5;
int n;

int solve(){
	int m;
	cin>>n>>m;
	ll l=m, r=m;
	bool ok = true;
	int ptime = 0;
	for(int i=0; i<n; i++) {
		ll time, low, up;
		cin>>time>>low>>up;
		ll d = time - ptime;
		l -= d;
		r += d;
		if((l < low && r < low) || (l > up && r > up)) {
			ok = false;
			break;
		}
		else{
			l = max(l, low);
			r = min(r, up);
			ptime = time;
		}
		// cout<<l<<" "<<r<<endl;
	}
	if(ok) {
		cout<<"yes\n";
	}
	else{
		cout<<"no\n";
	}
	// cout<<endl<<endl;
}

int main(){
	fast;
	ll testcase;
	cin>>testcase;
	 // testcase = 1;
	while(testcase--) {
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1e5 + 5;
int n;

int solve(){
	int m;
	cin>>n>>m;
	ll l=m, r=m;
	bool ok = true;
	ll ptime = 0;
	for(int i=0; i<n; i++) {
		ll time, low, up;
		cin>>time>>low>>up;
		ll d = time - ptime;
		l -= d;
		r += d;
		if((l < low && r < low) || (l > up && r > up)) {
			ok = false;
			break;
		}
		else{
			l = max(l, low);
			r = min(r, up);
			ptime = time;
		}
		// cout<<l<<" "<<r<<endl;
	}
	if(ok) {
		cout<<"yes\n";
	}
	else{
		cout<<"no\n";
	}
	// cout<<endl<<endl;
}

int main(){
	fast;
	ll testcase;
	cin>>testcase;
	 // testcase = 1;
	while(testcase--) {
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1e5 + 5;
int n;

int solve(){
	int m;
	cin>>n>>m;
	ll l=m, r=m;
	bool ok = true;
	ll ptime = 0;
	for(int i=0; i<n; i++) {
		ll time, low, up;
		cin>>time>>low>>up;
		ll d = time - ptime;
		l -= d;
		r += d;
		if(( r < low) || ( l > up)) {
			ok = false;
			break;
		}
		else{
			l = max(l, low);
			r = min(r, up);
			ptime = time;
		}
		// cout<<l<<" "<<r<<endl;
	}
	if(ok) {
		cout<<"yes\n";
		return 0;
	}
	else{
		cout<<"no\n";
		return 0;
	}
	// cout<<endl<<endl;
}

int main(){
	fast;
	ll testcase;
	cin>>testcase;
	 // testcase = 1;
	while(testcase--) {
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1e5 + 5;
int n;

int solve(){
	int m;
	cin>>n>>m;
	ll l=m, r=m;
	bool ok = true;
	ll ptime = 0;
	for(int i=0; i<n; i++) {
		ll time, low, up;
		cin>>time>>low>>up;
		ll d = time - ptime;
		l -= d;
		r += d;
		if(( r < low) || ( l > up)) {
			ok = false;
			break;
		}
		else{
			l = max(l, low);
			r = min(r, up);
			ptime = time;
		}
		// cout<<l<<" "<<r<<endl;
	}
	if(ok) {
		cout<<"yes\n";
	}
	else{
		cout<<"no\n";
	}
	// cout<<endl<<endl;
}

int main(){
	fast;
	ll testcase;
	cin>>testcase;
	 // testcase = 1;
	while(testcase--) {
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1e5 + 5;
int n;

int solve(){
	int m;
	cin>>n>>m;
	ll l=m, r=m;
	bool ok = true;
	ll ptime = 0;
	for(int i=0; i<n; i++) {
		ll time, low, up;
		cin>>time>>low>>up;
		ll d = time - ptime;
		l -= d;
		r += d;
		if(( r < low) || ( l > up)) {
			ok = false;
			// break;
		}
		else{
			l = max(l, low);
			r = min(r, up);
			ptime = time;
		}
		// cout<<l<<" "<<r<<endl;
	}
	if(ok) {
		cout<<"yes\n";
		return 0;
	}
	else{
		cout<<"no\n";
		return 0;
	}
	// cout<<endl<<endl;
}

int main(){
	fast;
	ll testcase;
	cin>>testcase;
	 // testcase = 1;
	while(testcase--) {
		solve();
	}
}


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            mxx+=time;
            mnn-=time;

            if(mxx>=hi[i] && mnn<=lo[i])
            {
               mxx=hi[i];
               mnn=lo[i];
            }
            else if(hi[i]<mnn)
            {
                cout<<"NO"<<endl;goto A;

            }
            else if(lo[i]>mxx)
            {
               cout<<"NO"<<endl;goto A;

            }

           else if(mxx>=lo[i] && mnn<=lo[i])
           {

               mnn=lo[i];
           }
           else if(mxx>=hi[i] && mnn<=hi[i])
           {

               mxx=hi[i];
           }

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            mxx+=time;
            mnn-=time;

            mnn=max(lo[i], mnn), mxx=min(hi[i], mxx);

            if(mxx<mnn) {cout<<"NO"<<endl; goto A;}

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            mxx+=time;
            mnn-=time;

            time=ti[i];
            mnn=max(lo[i], mnn), mxx=min(hi[i], mxx);

            if(mxx<mnn) {cout<<"NO"<<endl; goto A;}

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            if(mxx>=hi[i] && mnn<=lo[i])
            {
               mxx=hi[i];
               mnn=lo[i];
            }
            else if(hi[i]<=mnn)
            {
                if(mnn-hi[i]>time) {cout<<"NO"<<endl;goto A;}

                mxx=hi[i];
                mnn=max(mnn-time, lo[i]);

            }
            else if(lo[i]>=mxx)
            {
                if(lo[i]-mxx>time) {cout<<"NO"<<endl;goto A;}

                mxx=min(mxx+time, hi[i] );
                mnn=lo[i];
            }
            else if(lo[i]<=mnn && hi[i]>=mxx)
            {
                mnn=max(lo[i], mnn-time);
                mxx=min(hi[i], mxx+time);
            }

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            if(mxx>=hi[i] && mnn<=lo[i])
            {
               mxx=hi[i];
               mnn=lo[i];
            }
            else if(hi[i]<mnn)
            {
                if(mnn-hi[i]>time) {cout<<"NO"<<endl;goto A;}

                mxx=hi[i];
                mnn=max(mnn-time, lo[i]);

            }
            else if(lo[i]>mxx)
            {
                if(lo[i]-mxx>time) {cout<<"NO"<<endl;goto A;}

                mxx=min(mxx+time, hi[i] );
                mnn=lo[i];
            }
            else if(lo[i]<=mnn && hi[i]>=mxx)
            {
                mnn=max(lo[i], mnn-time);
                mxx=min(hi[i], mxx+time);
            }

        }
        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            if(mxx>=hi[i] && mnn<=lo[i])
            {
               mxx=hi[i];
               mnn=lo[i];
            }
            else if(hi[i]<=mnn)
            {
                if(mnn-hi[i]>time) {cout<<"NO"<<endl;goto A;}

                mxx=hi[i];
                mnn=max(mnn-time, lo[i]);

            }
            else if(lo[i]>=mxx)
            {
                if(lo[i]-mxx>time) {cout<<"NO"<<endl;goto A;}

                mxx=min(mxx+time, hi[i] );
                mnn=lo[i];
            }
            else if(lo[i]<=mnn && hi[i]>=mxx)
            {
                mnn=max(lo[i], mnn-time);
                mxx=min(hi[i], mxx+time);
            }
           else if(mxx>=lo[i] && mnn<lo[i])
           {
               mxx=min(mxx+time, hi[i]);
               mnn=lo[i];
           }
           else if(mxx>hi[i] && mnn<=hi[i])
           {
               mnn=max(mnn-time, lo[i]);
               mxx=hi[i];
           }

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            if(mxx>=hi[i] && mnn<=lo[i])
            {
               mxx=hi[i];
               mnn=lo[i];
            }
            else if(hi[i]<mnn)
            {
                if(mnn-hi[i]>time) {cout<<"NO"<<endl;goto A;}

                mxx=hi[i];
                mnn=max(mnn-time, lo[i]);

            }
            else if(lo[i]>mxx)
            {
                if(lo[i]-mxx>time) {cout<<"NO"<<endl;goto A;}

                mxx=min(mxx+time, hi[i] );
                mnn=lo[i];
            }
            else if(lo[i]<=mnn && hi[i]>=mxx)
            {
                mnn=max(lo[i], mnn-time);
                mxx=min(hi[i], mxx+time);
            }
           else if(mxx>=lo[i] && mnn<=lo[i])
           {
               mxx=min(mxx+time, hi[i]);
               mnn=lo[i];
           }
           else if(mxx>=hi[i] && mnn<=hi[i])
           {
               mnn=max(mnn-time, lo[i]);
               mxx=hi[i];
           }

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include<bits/stdc++.h>

using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
//#define mod                     998244353
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)

int main()
{
    fast_in_out;

    Q
    {
        ll n , cur;
        cin>>n>>cur;

        ll mxx, mnn, time=0;
        ll ti[n+4], hi[n+4], lo[n+4];

        mxx=mnn=cur;

        for(int i=0; i<n; i++)
        {
            cin>>ti[i]>>lo[i]>>hi[i];

        }

        for(int i=0; i<n; i++)
        {

            time=ti[i]-time;

            if(mxx>=hi[i] && mnn<=lo[i])
            {
               mxx=hi[i];
               mnn=lo[i];
            }
            else if(hi[i]<mnn)
            {
                if(mnn-hi[i]>time) {cout<<"NO"<<endl;goto A;}

                mxx=hi[i];
                mnn=max(mnn-time, lo[i]);

            }
            else if(lo[i]>mxx)
            {
                if(lo[i]-mxx>time) {cout<<"NO"<<endl;goto A;}

                mxx=min(mxx+time, hi[i] );
                mnn=lo[i];
            }
            else if(lo[i]<=mnn && hi[i]>=mxx)
            {
                mnn=max(lo[i], mnn-time);
                mxx=min(hi[i], mxx+time);
            }
           else if(mxx>=lo[i] && mnn<=lo[i])
           {
               mxx=min(mxx+time, hi[i]);
               mnn=lo[i];
           }
           else if(mxx>=hi[i] && mnn<=hi[i])
           {
               mnn=max(mnn-time, lo[i]);
               mxx=hi[i];
           }

           time=ti[i];

        }

        cout<<"YES"<<endl;

        A: ;

    }

   return 0;
}

/*
4 17
5 10 20
10 25 26
15 30 30
17 31 31

*/


#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define MOD 1000000007
#define nl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    fastIO;
    int q;
    cin>>q;
    while(q--)
    {
        int n,i,ans=0;
        lli m,t=0,l,h;
        cin>>n>>m;
        l = h = m;
        for(i=0;i<n;i++)
        {
            lli tc,lc,hc,l1,l2,l3,h1,h2,h3,pair=0,count=0;
            cin>>tc>>lc>>hc;
            if(ans == -1)
                continue;
            l1 = l;
            h1 = h;
            l2 = l + abs(t-tc);
            h2 = h + abs(t-tc);
            l3 = l - abs(t-tc);
            h3 = h - abs(t-tc);
            t = tc;
            l = lc;
            h = hc;
            if(h1==lc || h2==lc || h3==lc)
            	continue;
            if(l1==hc || l2==hc || l3==hc)
            	continue;
            if(l1==lc || l2==lc || l3==lc)
            	continue;
            if(h1==hc || h2==hc || h3==hc)
            	continue;
            if(h1 > lc)
            {
                    pair = 1;
                    if(l1 > hc)
                        count++;
            }
            if(h2 > lc)
            {
                    pair = 1;
                    if(l2 > hc)
                        count++;
            }
            if(h3 > lc)
            {
                    pair = 1;
                    if(l3 > hc)
                        count++;
            }
            if(pair==0 || count==3)
                ans = -1;
        }
        if(ans == -1)
            cout<<"NO"<<nl;
        else
            cout<<"YES"<<nl;
    }
}


#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define MOD 1000000007
#define nl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    fastIO;
    int q;
    cin>>q;
    while(q--)
    {
        int n,i,ans=0;
        lli m,t=0,l,h,maxi,mini,tc_max=0;
        cin>>n>>m;
        l = h = m;
        maxi = mini = m;
        for(i=0;i<n;i++)
        {
            lli tc,lc,hc,l1,l2,l3,h1,h2,h3,pair=0,count=0;
            cin>>tc>>lc>>hc;
            if(tc > tc_max)
            {
            	maxi += (tc-tc_max);
                mini -= (tc-tc_max);
                tc_max = tc;
            }
            if(lc>maxi || hc<mini)
            {
            	ans = -1;
            	continue;
            }
            if(ans == -1)
                continue;
            l1 = l;
            h1 = h;
            l2 = l + abs(t-tc);
            h2 = h + abs(t-tc);
            l3 = l - abs(t-tc);
            h3 = h - abs(t-tc);
            t = tc;
            l = lc;
            h = hc;
            if(h1==lc || h2==lc || h3==lc)
            	continue;
            if(l1==hc || l2==hc || l3==hc)
            	continue;
            if(l1==lc || l2==lc || l3==lc)
            	continue;
            if(h1==hc || h2==hc || h3==hc)
            	continue;
            if(h1 > lc)
            {
                    pair = 1;
                    if(l1 > hc)
                        count++;
            }
            if(h2 > lc)
            {
                    pair = 1;
                    if(l2 > hc)
                        count++;
            }
            if(h3 > lc)
            {
                    pair = 1;
                    if(l3 > hc)
                        count++;
            }
            if(pair==0 || count==3)
                ans = -1;
        }
        if(ans == -1)
            cout<<"NO"<<nl;
        else
            cout<<"YES"<<nl;
    }
}


#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define MOD 1000000007
#define nl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    fastIO;
    int q;
    cin>>q;
    while(q--)
    {
        int n,i,ans=0;
        lli m,t=0,l,h,maxi1,maxi2=0;
        cin>>n>>m;
        l = h = m;
        maxi1 = abs(m);
        for(i=0;i<n;i++)
        {
            lli tc,lc,hc,l1,l2,l3,h1,h2,h3,pair=0,count=0;
            cin>>tc>>lc>>hc;
            if(tc > maxi2)
            {
            	maxi1 += (tc-maxi2);
                maxi2 = tc;
            }
            if(abs(lc)>maxi1 || abs(hc)>maxi1)
            {
            	ans = -1;
            	continue;
            }
            if(ans == -1)
                continue;
            l1 = l;
            h1 = h;
            l2 = l + abs(t-tc);
            h2 = h + abs(t-tc);
            l3 = l - abs(t-tc);
            h3 = h - abs(t-tc);
            t = tc;
            l = lc;
            h = hc;
            if(h1==lc || h2==lc || h3==lc)
            	continue;
            if(l1==hc || l2==hc || l3==hc)
            	continue;
            if(l1==lc || l2==lc || l3==lc)
            	continue;
            if(h1==hc || h2==hc || h3==hc)
            	continue;
            if(h1 > lc)
            {
                    pair = 1;
                    if(l1 > hc)
                        count++;
            }
            if(h2 > lc)
            {
                    pair = 1;
                    if(l2 > hc)
                        count++;
            }
            if(h3 > lc)
            {
                    pair = 1;
                    if(l3 > hc)
                        count++;
            }
            if(pair==0 || count==3)
                ans = -1;
        }
        if(ans == -1)
            cout<<"NO"<<nl;
        else
            cout<<"YES"<<nl;
    }
}


#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define MOD 1000000007
#define nl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    fastIO;
    int q;
    cin>>q;
    while(q--)
    {
        int n,i,ans=0;
        lli m,t=0,l,h,maxi=0;
        cin>>n>>m;
        l = h = m;
        for(i=0;i<n;i++)
        {
            lli tc,lc,hc,l1,l2,l3,h1,h2,h3,pair=0,count=0;
            cin>>tc>>lc>>hc;
            maxi = max(maxi,tc);
            if(abs(lc)>maxi || abs(hc)>maxi)
            {
            	ans = -1;
            	continue;
            }
            if(ans == -1)
                continue;
            l1 = l;
            h1 = h;
            l2 = l + abs(t-tc);
            h2 = h + abs(t-tc);
            l3 = l - abs(t-tc);
            h3 = h - abs(t-tc);
            t = tc;
            l = lc;
            h = hc;
            if(h1==lc || h2==lc || h3==lc)
            	continue;
            if(l1==hc || l2==hc || l3==hc)
            	continue;
            if(l1==lc || l2==lc || l3==lc)
            	continue;
            if(h1==hc || h2==hc || h3==hc)
            	continue;
            if(h1 > lc)
            {
                    pair = 1;
                    if(l1 > hc)
                        count++;
            }
            if(h2 > lc)
            {
                    pair = 1;
                    if(l2 > hc)
                        count++;
            }
            if(h3 > lc)
            {
                    pair = 1;
                    if(l3 > hc)
                        count++;
            }
            if(pair==0 || count==3)
                ans = -1;
        }
        if(ans == -1)
            cout<<"NO"<<nl;
        else
            cout<<"YES"<<nl;
    }
}