#include <bits/stdc++.h>
int main() {
  int n[100], a, b, c, i, t;
  do {
    printf("enter the number of test cases:");
    scanf("%d", &t);
  } while ((t < 1) || (t > 100));
  for (i = 0; i < t; i++) {
    n[i] = 0;
  }
  for (i = 0; i < t; i++) {
    do {
      printf(
          "Enter the number of stones in the first, the second and the third "
          "heap, respectively:");
      scanf("%d %d %d", &a, &b, &c);
    } while ((a < 0) || (b < 0) || (c < 0));
    do {
      if (b > c) {
        if ((a >= 1) && (b >= 2)) {
          a--;
          b = b - 2;
          n[i] = n[i] + 3;
        }
      } else if (c >= b) {
        if ((b >= 1) && (c >= 2)) {
          b--;
          c = c - 2;
          n[i] = n[i] + 3;
        }
      }
    } while ((a != 0) && (b != 0));
  }
  for (i = 0; i < t; i++) {
    printf("%d\n", n[i]);
  }
}
