#include <bits/stdc++.h>
using namespace std;
const double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230;
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
void sol() {
  long long int test_case;
  cin >> test_case;
  while (test_case--) {
    long long int zero1, zero2, one1, one2, two1, two2;
    cin >> zero1 >> one1 >> two1;
    cin >> zero2 >> one2 >> two2;
    long long int sum = 0;
    long long int v = min(two1, one2);
    sum += (2 * v);
    two1 -= v;
    one2 -= v;
    v = min(two1, two2);
    two1 -= v;
    two2 -= v;
    v = min(zero1, two2);
    zero1 -= v;
    two2 -= v;
    if (two2 > 0) {
      sum -= (2 * two2);
    }
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  sol();
}
