#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    int cont = 0;
    while (1) {
      if ((b == 0) || (c == 0) || (b == 1 && c == 1)) break;
      if (c >= b || a == 0) {
        b = b - 1;
        c = c - 2;
        cont += 3;
      } else {
        b = b - 2;
        a = a - 1;
        cont += 3;
      }
    }
    cout << cont << endl;
  }
  return 0;
}
