#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, aa, bb, cc;
    cin >> a >> b >> c >> aa >> bb >> cc;
    long long s = 0;
    int x = min(c, bb);
    s += 2 * x;
    c = c - x;
    bb = bb - x;
    x = min(a, cc);
    a = a - x;
    cc = cc - x;
    x = min(a, bb);
    a = a - x;
    bb = bb - x;
    x = min(a, aa);
    a = a - x;
    aa = aa - x;
    x = min(a, aa);
    a = a - x;
    aa = aa - x;
    x = min(b, bb);
    b = b - x;
    bb = bb - x;
    x = min(c, cc);
    c = c - x;
    cc = cc - x;
    x = min(b, cc);
    b = b - x;
    cc = cc - x;
    s -= x * 2;
    cout << s << endl;
  }
}
