#include <bits/stdc++.h>
using namespace std;
void solve() {
  int x1, x2, y1, y2, z1, z2;
  cin >> x1 >> y1 >> z1;
  cin >> x2 >> y2 >> z2;
  int ans = 0;
  ans += 2 * min(z1, y2);
  z1 -= min(z1, y2);
  z2 -= min(z2, z1 + x1);
  ans -= 2 * z2;
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
