#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
const int M = 1e5;
const int mod = 998244353;
const int inf = 2e9 + 3;
const long long INF = 1e16;
int T;
long long a[3], b[3];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%lld %lld %lld", &a[0], &a[1], &a[2]);
    scanf("%lld %lld %lld", &b[0], &b[1], &b[2]);
    long long mn = min(a[2], b[1]);
    long long ans = mn * 2LL;
    a[2] -= mn;
    b[1] -= mn;
    mn = min(b[1], a[1]);
    b[1] -= mn;
    a[1] -= mn;
    mn = min(b[0], a[1]);
    b[0] -= mn;
    a[1] -= mn;
    mn = min(b[2], a[0]);
    b[2] -= mn;
    a[0] -= mn;
    mn = min(b[2], a[2]);
    b[2] -= mn;
    a[2] -= mn;
    mn = min(b[2], a[1]);
    ans -= mn * 2LL;
    printf("%lld\n", ans);
  }
}
