#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b, c;
    int d, e, f;
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d%d%d", &d, &e, &f);
    int sum = 0;
    sum = min(c, e) * 2;
    e = e - sum / 2;
    c = c - sum / 2;
    if (c > 0) {
      f = f - min(c, f);
    }
    if (d + e < b) {
      sum = sum - min((b - d - e), f) * 2;
    }
    printf("%d\n", sum);
  }
  return 0;
}
