#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int i, j, k, a, b, c, x, y, z, n, m, t, ans;
  cin >> t;
  while (t--) {
    ans = 0;
    cin >> x >> y >> z;
    cin >> a >> b >> c;
    k = min(z, b);
    z -= k;
    b -= k;
    ans += 2 * k;
    k = min(z, c);
    z -= k;
    c -= k;
    k = min(c, x);
    x -= k;
    c -= k;
    k = min(y, c);
    y -= k;
    c -= k;
    ans -= 2 * k;
    cout << ans << "\n";
  }
}
