#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a0, a1, a2, b0, b1, b2;
    cin >> a0 >> a1 >> a2 >> b0 >> b1 >> b2;
    int n = min(a0, b2);
    a0 -= n;
    b2 -= n;
    n = min(b0, a1);
    a1 -= n;
    b0 -= n;
    cout << 2 * (min(a2, b1) - min(a1, b2)) << endl;
  }
  return 0;
}
