#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c, c1 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    if (c > 2 && b > 1) {
      c1 += 3;
      c = c - 2;
      b = b - 1;
    }
    if (a > 1 && b > 2) {
      c1 += 3;
      a = a - 1;
      b = b - 2;
    }
    cout << c1 << endl;
  }
  return 0;
}
