#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a1[3], a2[3], a, b, c, j, r, m, i, sum = 0;
  cin >> t;
  while (t--) {
    cin >> a1[0] >> a1[1] >> a1[2];
    cin >> a2[0] >> a2[1] >> a2[2];
    sum = 0;
    for (i = 2; i > 0; --i) {
      if (i == 2) {
        if (a2[1] > 0 and a1[i] > 0) {
          if (a1[i] >= a2[1])
            sum += 2 * a2[1];
          else
            sum += 2 * a1[i];
          r = a2[1];
          a2[1] -= a1[i];
          a1[i] -= r;
        }
        if (a2[2] > 0 and a1[i] > 0) {
          r = a2[2];
          a2[2] -= a1[i];
          a1[i] -= r;
        }
        if (a2[0] > 0 and a1[i] > 0) {
          r = a2[0];
          a2[0] -= a1[i];
          a1[i] -= r;
        }
      } else if (i == 1) {
        if (a2[1] > 0 and a1[i] > 0) {
          r = a2[1];
          a2[1] -= a1[i];
          a1[i] -= r;
        }
        if (a2[0] > 0 and a1[i] > 0) {
          r = a2[0];
          a2[0] -= a1[i];
          a1[i] -= r;
        }
        if (a2[2] > 0 and a1[i] > 0) {
          if (a1[i] >= a2[2])
            sum -= 2 * a2[2];
          else
            sum -= 2 * a1[i];
          r = a2[2];
          a2[2] -= a1[i];
          a1[i] -= r;
        }
      }
    }
    cout << sum << endl;
  }
}
