#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9 + 9;
const long long inf = 1e18 + 18;
const long long max6 = 1e6 + 6;
const long long modx = 1e9 + 123;
const long long mody = 997;
const long long base = 137;
long long a[5], b[5];
long long Pow(long long a, long long b) { return a * b; }
int main() {
  long long t;
  cin >> t;
  while (t--) {
    for (long long i = 0; i <= 2; ++i) cin >> a[i];
    for (long long i = 0; i <= 2; ++i) cin >> b[i];
    long long res = 0;
    long long tmp = min(a[2], b[1]);
    a[2] -= tmp, b[1] -= tmp;
    if (tmp) res += Pow(2, tmp);
    tmp = min(a[2], b[2]);
    a[2] -= tmp, b[2] -= tmp;
    tmp = min(a[0], b[2]);
    a[0] -= tmp, b[2] -= tmp;
    tmp = min(b[2], a[1]);
    a[1] -= tmp, b[2] -= tmp;
    if (tmp) res -= Pow(2, tmp);
    cout << res << "\n";
  }
}
