#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    cout << min(c, e) * 2 - 2 * (min(f - min(a, f), b - min(b, d))) << endl;
  }
}
