#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline bool read(T &x) {
  bool sign = 0;
  char ch = nc();
  x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return true;
}
inline bool read(double &x) {
  bool sign = 0;
  char ch = nc();
  x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (ch == '.') {
    double tmp = 1;
    ch = nc();
    for (; ch >= '0' && ch <= '9'; ch = nc())
      tmp /= 10.0, x += tmp * (ch - '0');
  }
  if (sign) x = -x;
  return true;
}
inline bool read(char *s) {
  char ch = nc();
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return false;
  for (; !blank(ch) && !IOerror; ch = nc()) *s++ = ch;
  *s = 0;
  return true;
}
inline bool read(char &c) {
  for (c = nc(); blank(c); c = nc())
    ;
  if (IOerror) {
    c = -1;
    return false;
  }
  return true;
}
template <class T, class... U>
bool read(T &h, U &...t) {
  return read(h) && read(t...);
}
};  // namespace fastIO
using namespace fastIO;
void DEBUGll(long long *a, int n) {
  for (int i = 0; i <= n; i++) printf("%lld%c", a[i], " \n"[i == n]);
}
void DEBUGint(int *a, int n) {
  for (int i = 0; i <= n; i++) printf("%d%c", a[i], " \n"[i == n]);
}
void freio() {}
const int MAXN = 2e5 + 5;
const int MAXM = MAXN << 1;
const int mod = 10007;
const int INF = 0X3f3f3f3f;
int a[3], b[3];
int main() {
  freio();
  int t;
  read(t);
  while (t--) {
    for (int i = 0; i < 3; i++) read(a[i]);
    for (int i = 0; i < 3; i++) read(b[i]);
    if (a[0] >= b[2]) {
      b[2] = 0;
      a[0] -= b[2];
    } else {
      b[2] -= a[0];
      a[0] = 0;
    }
    long long ans = 0;
    if (a[2] >= b[1]) {
      ans += b[1] * 2;
      a[2] -= b[1];
      b[1] = 0;
    } else {
      ans += a[2] * 2;
      a[2] = 0;
      b[1] -= a[2];
    }
    if (a[2] >= b[2]) {
      b[2] = 0;
      a[2] -= b[2];
    } else {
      b[2] -= a[2];
      a[2] = 0;
    }
    if (b[2]) {
      if (a[1] >= b[2]) {
        ans -= b[2] * 2;
      } else
        ans -= a[1] * 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
