#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t) {
    t--;
    int x1, x2, y1, y2, z1, z2;
    cin >> x1 >> y1 >> z1;
    cin >> x2 >> y2 >> z2;
    long long sum = 0;
    int tmp = 0;
    tmp = min(z1, y2);
    sum += 2 * tmp;
    z1 -= tmp;
    y2 -= tmp;
    tmp = min(y1, x2);
    y1 -= tmp;
    x2 -= tmp;
    tmp = min(x1, z2);
    x1 -= tmp;
    z2 -= tmp;
    tmp = min(y1, z2);
    sum -= 2 * tmp;
    cout << sum << '\n';
  }
  return 0;
}
