#include <bits/stdc++.h>
bool isPrime(long long n) {
  if (n % 2 == 0 || n % 3 == 0) return false;
  if (n <= 1) return false;
  if (n <= 3) return true;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
using namespace std;
void solve() {
  long long x, y, z;
  long long p, q, r;
  long long ans = 0;
  cin >> x >> y >> z >> p >> q >> r;
  int temp = min(z, q);
  ans = temp * 2;
  z -= temp;
  q -= temp;
  temp = min(x, r);
  x -= temp;
  r -= temp;
  temp = min(x, q);
  x -= temp;
  q -= temp;
  temp = min(x, p);
  x -= temp;
  p -= temp;
  temp = min(y, p);
  y -= temp;
  p -= temp;
  temp = min(y, q);
  y -= temp;
  q -= temp;
  if (y && r) {
    ans -= y * 2;
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, tt = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
