#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
void header() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long X1, Y1, Z1, X2, Y2, Z2;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    cin >> X1 >> Y1 >> Z1;
    cin >> X2 >> Y2 >> Z2;
    long long mi = min(X1, Z2), res = 0;
    X1 -= mi, Z2 -= mi;
    if (Z1 < Z2)
      res = (min(Y1 - min(Y1, Y2), Z2 - Z1) << 1) * (-1);
    else
      res = min(Y2, Z1 - Z2) << 1;
    cout << res << '\n';
  }
}
int main() {
  header();
  solve();
  return 0;
}
