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