#include <bits/stdc++.h>
using namespace std;
int n;
int x[10];
int res = 0;
void dfs(int a, int b, int c, int sum) {
  if (b == 0 || (a == 0 && c <= 1)) {
    res = max(res, sum);
    return;
  }
  if (a - 1 >= 0 && b - 2 >= 0) {
    sum += 3;
    dfs(a - 1, b - 2, c, sum);
    sum -= 3;
  }
  if (b - 1 >= 0 && c - 2 >= 0) {
    sum += 3;
    dfs(a, b - 1, c - 2, sum);
    sum -= 3;
  }
  return;
}
int main() {
  cin >> n;
  for (int pp = 0; pp < n; pp++) {
    for (int i = 0; i < 3; i++) cin >> x[i];
    dfs(x[0], x[1], x[2], 0);
    cout << res << endl;
    res = 0;
  }
  return 0;
}
