#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b, c, count;
  cin >> t;
  while (t--) {
    count = 0;
    cin >> a >> b >> c;
    if (b == 0) {
      cout << 0 << "\n";
      continue;
    }
    if (a == 0) {
      if (b >= (c / 2) && c > 0) {
        count += ((c / 2) + (2 * (c / 2)));
        c = c - (2 * (c / 2));
      } else if (c > 0) {
        count += (3 * b);
        c = c - (2 * b);
      }
      cout << count << "\n";
      continue;
    }
    if (c == 0) {
      if (a >= (b / 2) && b > 0) {
        count += ((b / 2) + (2 * (b / 2)));
        b = b - (2 * (b / 2));
      } else if (b > 0) {
        count += (3 * a);
        b = b - (2 * a);
      }
      cout << count << "\n";
      continue;
    }
    if (a > c) {
      if (a >= (b / 2)) {
        count += ((b / 2) + (2 * (b / 2)));
        b = b - (2 * (b / 2));
      } else {
        count += (3 * a);
        b = b - (2 * a);
      }
      if (b >= (c / 2) && c > 0) {
        count += ((c / 2) + (2 * (c / 2)));
        c = c - (2 * (c / 2));
      } else {
        if (c > 0) {
          count += (3 * b);
          c = c - (2 * b);
        }
      }
    } else {
      if (b >= (c / 2)) {
        count += ((c / 2) + (2 * (c / 2)));
        b = b - (c / 2);
      } else {
        count += (3 * b);
        b = b - (c / 2);
      }
      if (a >= (b / 2) && b > 0) {
        count += ((b / 2) + (2 * (b / 2)));
        b = b - (2 * (b / 2));
      } else {
        if (b > 0) {
          count += (3 * a);
          b = b - (2 * a);
        }
      }
    }
    cout << count << "\n";
  }
  return 0;
}
