#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    int stones = 0;
    if (b > c) {
      while (1) {
        if (a >= 1 && b >= 2) {
          stones = stones + 3;
          a = a - 1;
          b = b - 2;
        } else
          break;
      }
      while (1) {
        if (b >= 1 && c >= 2) {
          stones = stones + 3;
          b = b - 1;
          c = c - 2;
        } else {
          break;
        }
      }
      cout << stones << endl;
      continue;
    }
    if (c >= b) {
      while (1) {
        if (b >= 1 && c >= 2) {
          stones = stones + 3;
          b = b - 1;
          c = c - 2;
        } else {
          break;
        }
      }
      while (1) {
        if (a >= 1 && b >= 2) {
          stones = stones + 3;
          a = a - 1;
          b = b - 2;
        } else
          break;
      }
      cout << stones << endl;
      continue;
    }
    if (b == c) {
      if (a > b) {
        while (1) {
          if (a >= 1 && b >= 2) {
            stones = stones + 3;
            a = a - 1;
            b = b - 2;
          } else
            break;
        }
        while (1) {
          if (b >= 1 && c >= 2) {
            stones = stones + 3;
            b = b - 1;
            c = c - 2;
          } else {
            break;
          }
        }
        cout << stones << endl;
        continue;
      }
      if (b > a) {
        while (1) {
          if (b >= 1 && c >= 2) {
            stones = stones + 3;
            b = b - 1;
            c = c - 2;
          } else {
            break;
          }
        }
        while (1) {
          if (a >= 1 && b >= 2) {
            stones = stones + 3;
            a = a - 1;
            b = b - 2;
          } else
            break;
        }
        cout << stones << endl;
        continue;
      }
      int stones1 = 0, stones2 = 0;
      if (a == b) {
        int t1 = a;
        int t2 = b;
        int t3 = c;
        while (1) {
          if (t1 >= 1 && t2 >= 2) {
            stones1 = stones1 + 3;
            t1 = t1 - 1;
            t2 = t2 - 2;
          } else
            break;
        }
        while (1) {
          if (t2 >= 1 && t3 >= 2) {
            stones1 = stones1 + 3;
            t2 = t2 - 1;
            t3 = t3 - 2;
          } else {
            break;
          }
        }
        int t4 = a, t5 = b, t6 = c;
        while (1) {
          if (t5 >= 1 && t6 >= 2) {
            stones2 = stones2 + 3;
            t5 = t5 - 1;
            t6 = t6 - 2;
          } else {
            break;
          }
        }
        while (1) {
          if (t4 >= 1 && t5 >= 2) {
            stones2 = stones2 + 3;
            t4 = t4 - 1;
            t5 = t5 - 2;
          } else
            break;
        }
        if (stones1 <= stones2) {
          cout << stones1 << endl;
          continue;
        } else {
          cout << stones2 << endl;
          continue;
        }
      }
    }
  }
}
