#include <bits/stdc++.h>
using namespace std;
long long ans, a[3], b[3], t, c[3];
signed main() {
  cin >> t;
  while (t--) {
    for (long long i = 1; i <= 2; i++) cin >> a[i] >> b[i] >> c[i];
    if (c[1] > b[2]) {
      ans = 2 * b[2];
      long long left = c[2] - (c[1] - b[2] + a[1]);
      if (left < 0) left = 0;
      ans -= 2 * left;
    } else {
      ans = 2 * c[1];
      long long left = b[1] - (b[2] - c[1] + a[2]);
      if (left < 0) left = 0;
      ans -= 2 * left;
    }
    cout << ans << endl;
  }
}
