#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int x1, y1, z1, x2, y2, z2;
    cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
    long long int aa = 0;
    if (z1 == y2) {
      long long int sum = 0;
      sum += 2 * z1;
      sum += (-2) * max(y1 - x2, aa);
      cout << sum << endl;
      continue;
    } else if (z1 > y2) {
      long long int sum = 0;
      sum += 2 * y2;
      sum += (-2) * max(z2 - (z1 - y2 + x1), aa);
      cout << sum << endl;
      continue;
    } else {
      long long int sum = 0;
      sum += 2 * z1;
      sum += (-2) * max(y1 - (y2 - z1 + x2), aa);
      cout << sum << endl;
      continue;
    }
  }
}
