#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
vector<int> prime;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x0, x1, x2, y0, y1, y2, ans = 0LL, mn;
    cin >> x0 >> x1 >> x2 >> y0 >> y1 >> y2;
    mn = min(x0, y2);
    x0 -= mn;
    y2 -= mn;
    mn = min(x1, y0);
    x1 -= mn;
    y0 -= mn;
    mn = min(x2, y1);
    x2 -= mn;
    y1 -= mn;
    ans += 2LL * mn;
    mn = min(x1, y2);
    ans -= 2LL * mn;
    cout << ans << endl;
  }
  return 0;
}
