#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int INF = int(1e9), mod = 1000000007, N = int(1e5) + 5;
const long long BIG = 100000000000000;
const double PI = 3.141592653589793238463;
int a[5];
int main() {
  int t;
  cin >> t;
  for (int tc = 1; tc <= t; tc++) {
    for (int i = 1; i <= 3; i++) {
      cin >> a[i];
    }
    int k = 0, p = 0;
    while (true) {
      if (a[2] >= 1 && a[3] >= 2) {
        a[3] -= 2;
        a[2] -= 1;
        k += 3;
      }
      if (a[1] >= 1 && a[2] >= 2) {
        a[2] -= 2;
        a[1] -= 1;
        k += 3;
      }
      if (k == p) {
        break;
      }
      p = k;
    }
    cout << k << endl;
  }
}
