#include <bits/stdc++.h>
inline long long MinAndUpd(int &x1, int &x2) {
  int tmp = std::min(x1, x2);
  x1 -= tmp;
  x2 -= tmp;
  return tmp;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int t;
  std::cin >> t;
  while (t--) {
    long long ans = 0;
    int a[3], b[3];
    std::cin >> a[0] >> a[1] >> a[2];
    std::cin >> b[0] >> b[1] >> b[2];
    ans += 1LL * MinAndUpd(a[2], b[1]) * 2;
    MinAndUpd(b[2], a[2]);
    MinAndUpd(b[2], a[0]);
    ans -= 1LL * MinAndUpd(b[2], a[1]) * 2;
    std::cout << ans << "\n";
  }
}
