#include <bits/stdc++.h>
using namespace std;
int sort3(int arr[]) {
  if (arr[1] < arr[0]) swap(arr[0], arr[1]);
  if (arr[2] < arr[1]) {
    swap(arr[1], arr[2]);
    if (arr[1] < arr[0]) swap(arr[1], arr[0]);
  }
}
int main() {
  int ax[5];
  int a, b, c, cnt = 0, t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    ax[0] = a;
    ax[1] = b;
    ax[2] = c;
    if (ax[1] == 0)
      cout << "0" << endl;
    else {
      sort3(ax);
      while ((ax[1] > 1 || ax[1] == 1) && (ax[2] > 2 || ax[2] == 2)) {
        ax[1] = ax[1] - 1;
        ax[2] = ax[2] - 2;
        cnt = cnt + 3;
      }
      while ((ax[1] > 2 || ax[1] == 2) && (ax[0] > 1 || ax[0] == 1)) {
        ax[0] = ax[0] - 1;
        ax[1] = ax[1] - 2;
        cnt = cnt + 3;
      }
      cout << cnt << endl;
      cnt = 0;
    }
  }
}
