#include <bits/stdc++.h>
using namespace std;
void rlmn() {
  int x0, x1, x2, y0, y1, y2;
  scanf("%d%d%d%d%d%d", &x0, &x1, &x2, &y0, &y1, &y2);
  int ans;
  if (x2 > y1) {
    ans = 2 * y1;
    x2 -= y1;
    y1 = 0;
  } else {
    ans = 2 * x2;
    x2 = 0;
    y1 -= x2;
  }
  y2 -= (x0 + x2);
  if (y2 <= 0) {
    printf("%d\n", ans);
  } else {
    printf("%d\n", ans - 2 * y2);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) rlmn();
  return 0;
}
