#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
const long long MOD = 1000000007;
void solve() {
  vector<int> a(3), b(3);
  for (auto &(z) : a) cin >> z;
  ;
  for (auto &(z) : b) cin >> z;
  ;
  int ans = 0;
  int v = min(a[2], b[1]);
  a[2] -= v, b[1] -= v;
  ans += 2 * v;
  v = min(a[0], b[2]);
  a[0] -= v, b[2] -= v;
  v = min(a[1], b[0]);
  a[1] -= v, b[0] -= v;
  v = min(a[1], b[2]);
  ans -= 2 * v;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
