#include <bits/stdc++.h>
using namespace ::std;
int nxt() {
  int x;
  cin >> x;
  return x;
}
long long nxtll() {
  long long x;
  cin >> x;
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = nxt();
  for (int _ = 0; _ < t; _++) {
    long long x1, x2, y1, y2, z1, z2;
    cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
    long long sum = 0;
    long long left_z2 = max(0LL, z2 - x1);
    long long left_x1 = max(0LL, x1 - z2);
    long long left_z1 = max(0LL, z1 - left_z2);
    left_z2 = max(0LL, left_z2 - z1);
    long long left_y1 = max(0LL, y1 - left_z2);
    sum = sum - 2 * left_z2;
    long long spent = min(y2, left_z1);
    long long left_y2 = max(0LL, y2 - left_z1);
    sum = sum + 2 * spent;
    cout << sum << endl;
  }
  return 0;
}
