import java.util.Scanner;
public class Stones {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int query = scan.nextInt();
        for (int x = 0; x < query; x++) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            int c = scan.nextInt();
            int op1 = 0;
            int op2 = 0;
            if (a >= 1 & b >= 2) {
                a = a - 1;
                b = b - 2;
                op1 = a + b + c;
                a = a + 1;
                b = b + 2;
            }
            if (b >= 1 & c >= 2) {
                b = b - 1;
                c = c - 2;
                op2 = a + b + c;
                b = b + 1;
                c = c + 2;
            }
            if (op1 >= op2) {
                System.out.println(op1);
            }
            else {
                System.out.println(op2);
            }
        }
    }
}