#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a[3];
    int b[3];
    cin >> a[0] >> a[1] >> a[2];
    cin >> b[0] >> b[1] >> b[2];
    int c[3];
    c[0] = min(a[2], b[1]);
    int ans = 0;
    ans += c[0] * 2;
    int res = a[0] + (a[2] - c[0]);
    if (res >= b[2]) cout << ans << endl;
    if (res < b[2]) {
      cout << ans - (b[2] - res) * 2 << endl;
    }
  }
  return 0;
}
