#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long a, b, c, d, e, f;
    cin >> a >> b >> c;
    cin >> d >> e >> f;
    long long cnt = 0;
    if (c > e) {
      cnt = cnt + 2 * e;
      c = c - e;
      e = 0;
    } else {
      cnt = cnt + 2 * c;
      e = e - c;
      c = 0;
    }
    long long neg1 = 0, neg2 = 0;
    if (a + c < f) neg1 = f - (a + c);
    if (d + e < b) neg2 = b - (d + e);
    if (neg1 == neg2) cnt = cnt - 2 * neg1;
    cout << cnt;
    cout << "\n";
  }
}
