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