#include <bits/stdc++.h>
int main() {
  int t, a, b, c, i, m, n, x;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d%d%d", &a, &b, &c);
    m = a + b + c;
    if (b = c) {
      while (b > 0 && c > 1) {
        b = b - 1;
        c = c - 2;
      }
      while (a > 0 && b > 1) {
        a = a - 1;
        b = b - 2;
      }
    } else if (b > c) {
      while (a > 0 && b > 1) {
        a = a - 1;
        b = b - 2;
      }
      while (b > 0 && c > 1) {
        b = b - 1;
        c = c - 2;
      }
    } else if (c > b) {
      while (b > 0 && c > 1) {
        b = b - 1;
        c = c - 2;
      }
      while (a > 0 && b > 1) {
        a = a - 1;
        b = b - 2;
      }
    }
    n = a + b + c;
    x = m - n;
    printf("%d\n", x);
  }
  return 0;
}
