#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a0, a1, a2, b0, b1, b2;
  cin >> a0 >> a1 >> a2 >> b0 >> b1 >> b2;
  long long sm = 0;
  long long mx21 = min(a2, b1);
  sm = mx21 * 2;
  a2 = a2 - mx21;
  b1 = b1 - mx21;
  long long mx02 = min(a0, b2);
  a0 = a0 - mx02;
  b2 = b2 - mx02;
  long long mx22 = min(a2, b2);
  a2 = a2 - mx22;
  b2 = b2 - mx22;
  long long mx20 = min(a2, b0);
  a2 = a2 - mx20;
  b0 = b0 - mx20;
  long long mx01 = min(a0, b1);
  a0 = a0 - mx01;
  b1 = b1 - mx01;
  long long mx00 = min(a0, b0);
  a0 = a0 - mx00;
  b0 = b0 - mx00;
  long long mx10 = min(a1, b0);
  a1 = a1 - mx10;
  b0 = b0 - mx10;
  long long mx11 = min(a1, b1);
  a1 = a1 - mx11;
  b1 = b1 - mx11;
  long long mx12 = min(a1, b2);
  sm = sm - mx12 * 2;
  cout << sm << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
