#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 0x7fffffff;
const int in = 1e9 + 7;
int a[N], b[N], c[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a0, a1, a2, b0, b1, b2;
    scanf("%d %d %d %d %d %d", &a0, &a1, &a2, &b0, &b1, &b2);
    long long ans = 0;
    int ans1 = min(a2, b1);
    ans += 2 * ans1;
    a2 -= ans1;
    b1 -= ans1;
    a1 -= (b0 + b1);
    if (a1 > 0) ans -= a1 * 2;
    cout << ans << endl;
  }
  return 0;
}
