#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b == 0)
      cout << 0 << endl;
    else {
      int cnt = 0;
      queue<int> qa;
      queue<int> qb;
      queue<int> qc;
      for (int i = 0; i < a; ++i) qa.push(i);
      for (int i = 0; i < b; ++i) qb.push(i);
      for (int i = 0; i < c; ++i) qc.push(i);
      while (1) {
        int max1 = qa.size();
        if (max1 < qb.size()) max1 = qb.size();
        if (max1 < qc.size()) max1 = qc.size();
        int max2;
        if (qa.size() != max1)
          max2 = qa.size();
        else
          max2 = qb.size();
        if (qb.size() > max2 && qb.size() != max1) max2 = qb.size();
        if (qc.size() > max2 && qc.size() != max1) max2 = qc.size();
        if (((max1 == qa.size() && max2 == qb.size()) ||
             max1 == qb.size() && max2 == qc.size()) &&
            max1 >= 1 && max2 >= 2) {
          cnt += 3;
          qa.pop();
          qb.pop();
          qb.pop();
        } else if (((max1 == qb.size() && max2 == qc.size()) ||
                    max1 == qc.size() && max2 == qb.size()) &&
                   max1 >= 1 && max2 >= 2) {
          cnt += 3;
          qb.pop();
          qc.pop();
          qc.pop();
        } else {
          cnt += 3;
          break;
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}
