#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a[3], b[3];
    for (int i = 0; i < 3; ++i) cin >> a[i];
    for (int i = 0; i < 3; ++i) cin >> b[i];
    int sum(0), m, n;
    n = a[0] + a[1] + a[2];
    m = min(a[2], b[1]);
    sum += 2 * m;
    n -= m;
    sum -= 2 * max(0, a[1] + b[2] - n);
    cout << sum << endl;
  }
}
