#include <bits/stdc++.h>
using namespace std;
void solve(vector<int>& a, vector<int>& b) {
  int res = 0;
  res += 2 * (min(a[2], b[1]));
  a[2] -= min(a[2], b[1]);
  b[1] -= min(a[2], b[1]);
  b[2] -= min(b[2], a[0]);
  a[0] -= min(a[0], b[2]);
  b[2] -= min(b[2], a[2]);
  res -= 2 * min(b[2], a[1]);
  cout << res << endl;
}
int main() {
  int t;
  cin >> t;
  while (t) {
    vector<int> a(3);
    vector<int> b(3);
    for (int i = 0; i < 3; i++) cin >> a[i];
    for (int i = 0; i < 3; i++) cin >> b[i];
    solve(a, b);
    t--;
  }
  return 0;
}
