#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x1, x2, x3;
    int y1, y2, y3;
    cin >> x1 >> x2 >> x3;
    cin >> y1 >> y2 >> y3;
    int ans = 0;
    int red0 = min(x1, y3);
    y3 -= red0;
    x1 -= red0;
    int red2 = min(x3, y3);
    y3 -= red2;
    x3 -= red2;
    int red1 = min(y3, x2);
    ans -= 2 * red1;
    y3 -= red1;
    x2 -= red1;
    int delet1 = min(x3, y2);
    ans += 2 * delet1;
    x3 -= delet1;
    y2 -= delet1;
    cout << ans << endl;
  }
  return 0;
}
