#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long x1, y1, z1, x2, y2, z2;
    cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
    long long ans = 0;
    long long tmp = min(z1, y2);
    z1 -= tmp;
    y2 -= tmp;
    ans += 2 * tmp;
    tmp = min(z1, z2);
    z1 -= tmp;
    z2 -= tmp;
    tmp = min(z1, x2);
    z1 -= tmp;
    x2 -= tmp;
    tmp = min(y1, y2);
    y1 -= tmp;
    y2 -= tmp;
    tmp = min(y1, x2);
    y1 -= tmp;
    x2 -= tmp;
    tmp = min(x1, z2);
    x1 -= tmp;
    z2 -= tmp;
    tmp = min(x1, y2);
    x1 -= tmp;
    y2 -= tmp;
    tmp = min(x1, x2);
    x1 -= tmp;
    x2 -= tmp;
    tmp = min(y1, z2);
    y1 -= tmp;
    z2 -= tmp;
    ans -= 2 * tmp;
    cout << ans << "\n";
  }
  return 0;
}
