#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, max = 0;
  int a[3];
  int k = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> a[0] >> a[1] >> a[2];
    while (a[k] > 0 && a[k + 1] > 1) {
      a[k]--;
      a[k + 1] -= 2;
      max += 3;
    }
    k = (k == 1) ? 0 : 1;
    while (a[k] > 0 && a[k + 1] > 1) {
      a[k]--;
      a[k + 1] -= 2;
      max += 3;
    }
    cout << max << endl;
    max = 0;
  }
}
