#include <bits/stdc++.h>
using namespace std;
int n, a, b, c;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  while (n--) {
    cin >> a >> b >> c;
    int kq = 0;
    for (int x = 1; x <= 300; x++)
      if (a >= x && b >= x * 2)
        for (int y = 1; y <= 300; y++)
          if (b >= 2 * x + y && c >= 2 * y) kq = max(kq, x + y);
    cout << kq * 3 << '\n';
  }
  return 0;
}
