#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, x, y, z, ans = 0;
    cin >> a >> b >> c >> x >> y >> z;
    int tmp = min(c, y);
    ans += (2 * min(c, y));
    y = (y > tmp) ? (y - tmp) : 0;
    b = (b > (x + y)) ? (b - (x + y)) : 0;
    ans -= (b * 2);
    cout << ans << endl;
  }
  return 0;
}
