#include <bits/stdc++.h>
using namespace std;
const long long int M = (long long int)1e9 + 7;
void solve() {
  long long int x1, y1, z1;
  long long int x2, y2, z2;
  cin >> x1 >> y1 >> z1;
  cin >> x2 >> y2 >> z2;
  long long int ans = 0;
  long long int z = min(z1, y2);
  ans = 2 * z;
  y1 = y1 - (x2 + y2 - z);
  if (y1 <= 0) {
    cout << ans << "\n";
  } else {
    ans = ans - 2 * y1;
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
