#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int a[3], b[3];
    for (int i = 0; i < 3; ++i) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < 3; ++i) {
      scanf("%d", &b[i]);
    }
    int n, sum(0), m;
    n = a[0] + a[1] + a[2];
    m = min(a[2], b[1]);
    sum += 2 * m;
    n -= m;
    sum -= 2 * max(0, a[1] + b[2] - n);
    printf("%d\n", sum);
  }
  return 0;
}
