#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int x1, y1, z1;
    long long int x2, y2, z2;
    cin >> x1 >> y1 >> z1;
    cin >> x2 >> y2 >> z2;
    long long int c = 0;
    c += 2 * min(z1, y2);
    int mn = min(z1, y2);
    z1 -= mn;
    y2 -= mn;
    mn = min(z1, z2);
    z1 -= mn;
    z2 -= mn;
    mn = min(z1, x2);
    z1 -= mn;
    x2 -= mn;
    mn = min(y1, x2);
    y1 -= mn;
    x2 -= mn;
    mn = min(y1, y2);
    y1 -= mn;
    y2 -= mn;
    mn = min(x1, z2);
    x1 -= mn;
    z2 -= mn;
    mn = min(y1, z2);
    c -= 2 * mn;
    y1 -= mn;
    z2 -= mn;
    mn = min(x1, y2);
    x1 -= mn;
    y2 -= mn;
    mn = min(x1, x2);
    mn = min(x1, x2);
    x1 -= mn;
    x2 -= mn;
    cout << c << endl;
  }
  return 0;
}
