#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
template <typename T>
void db(T x) {
  debug() << ">>> " << x;
}
template <typename T>
void db(T x, T y) {
  debug() << ">>> " << x << " , " << y;
}
template <typename T>
void db(T x, T y, T z) {
  debug() << ">>> " << x << " , " << y << " , " << z;
}
template <typename T>
void db(T x, T y, T z, T a) {
  debug() << ">>> " << x << " , " << y << " , " << z << " , " << a;
}
const long long xx = 2e5;
const long long Mod = 1e9 + 7;
const long long inf = 1e18;
const long long Maxn = 20010;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a0, a1, a2;
    long long b0, b1, b2;
    cin >> a0 >> a1 >> a2;
    cin >> b0 >> b1 >> b2;
    long long ans = 0;
    long long x = min(a2, b1);
    ans += x * 2;
    a2 -= x, b1 -= x;
    long long a = min(b2, a0);
    b2 -= a;
    a0 -= a;
    long long b = min(a2, b2);
    a2 -= b;
    b2 -= b;
    long long y = min(a1, b1);
    a1 -= y;
    b1 -= y;
    long long z = min(b2, a1);
    ans -= (z * 2);
    cout << ans << '\n';
  }
}
