#include <bits/stdc++.h>
using namespace std;
const double v = 1.41421356237;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int x1, y1, z1, x2, y2, z2;
    cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
    long long int m, sum = 0;
    m = min(z1, y2);
    sum += (2 * m);
    m = min(x1, z2);
    x1 -= m;
    z2 -= m;
    m = min(y1, x2);
    y1 -= m;
    x2 -= m;
    sum -= (2 * min(y1, z2));
    cout << sum << endl;
  }
}
