#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 5;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long t;
  cin >> t;
  long long T = t;
  while (t--) {
    long long a[3], b[3];
    for (long long i = 0; i < 3; i++) cin >> a[i];
    for (long long i = 0; i < 3; i++) cin >> b[i];
    long long n = a[0] + a[1] + a[2];
    long long ans = 0;
    long long mini = min(b[2], a[0]);
    b[2] -= mini;
    a[0] -= mini;
    mini = min(b[2], a[2]);
    b[2] -= mini;
    a[2] -= mini;
    ans -= (b[2] * 2);
    mini = min(a[2], b[1]);
    a[2] -= mini;
    b[1] -= mini;
    ans += (2 * mini);
    cout << ans << "\n";
  }
}
