#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  ll i, j;
  ll x1, y1, z1, x2, y2, z2;
  cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
  ll ans = 0;
  ll k = min(z1, y2);
  ans += k * 2;
  z1 -= k;
  y2 -= k;
  k = min(z2, z1);
  z2 -= k;
  z1 -= k;
  k = min(x1, z2);
  z2 -= k;
  x1 -= k;
  ans -= z2 * 2;
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
