#include <bits/stdc++.h>
using namespace std;
long double pi = 2.0 * acos(0.0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int a, b, c, i, j, k, first, r, x, y, z;
  long long int n, m, p, q, t;
  long long int A[1000005];
  memset(A, -1, sizeof(A));
  cin >> t;
  while (t--) {
    r = first = 0;
    cin >> a >> b >> c;
    cin >> x >> y >> z;
    i = min(c, y);
    r += i * 2;
    c -= i;
    y -= i;
    if (b <= (x + y)) {
    } else {
      b -= (x + y);
      r -= (b)*2;
    }
    cout << r << "\n";
  }
  return 0;
}
