#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long x1, y1, z1;
    long long x2, y2, z2;
    cin >> x1 >> y1 >> z1;
    cin >> x2 >> y2 >> z2;
    int mn = min(z1, y2);
    z1 -= mn;
    long long ans = 2LL * mn;
    long long tot = x1 + z1;
    int rem = max(0LL, z2 - tot);
    ans -= 2 * rem;
    cout << ans << endl;
  }
  return 0;
}
