#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long long x1, x2, y1, y2, z1, z2, ans, h;
  scanf("%d", &t);
  while (t--) {
    ans = 0;
    scanf("%lld%lld%lld%lld%lld%lld", &x1, &y1, &z1, &x2, &y2, &z2);
    h = min(z1, y2);
    ans += h * 2;
    z1 -= h;
    y2 -= h;
    h = min(z2, x1);
    z2 -= h;
    x1 -= h;
    h = min(x1, y2);
    x1 -= h;
    y2 -= h;
    h = min(x2, y1);
    x2 -= h;
    y1 -= h;
    h = min(y1, z2);
    ans -= h * 2;
    printf("%lld\n", ans);
  }
  return 0;
}
