#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, x, y, z;
    cin >> a >> b >> c;
    cin >> x >> y >> z;
    int t = min(c, y);
    c -= t;
    if (z > a + c) t -= z - a - c;
    cout << 2 * t << "\n";
  }
}
