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