import java.util.Scanner;

public class A2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int count=0;
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if(b==0){
                System.out.println(0);
                continue;
            }
            if(a>c){
                if(a > 0 && b > 1){
                    if(a>b/2){
                        int y = b/2;
                        a-=y;
                        count += 3*y;}
                    else if(a<b/2){
                        count +=3*a;
                    }
                }
                if(b > 0 && c > 1){
                    if(b>c/2){
                        int x = c/2;
                        b-=x;
                        count += 3*x;}
                    else if(b<c/2){
                        count += 3*b;
                        b-=b;
                    }
                }
            }
            else {
                if (b > 0 && c > 1) {
                    if (b > c / 2) {
                        int x = c / 2;
                        b -= x;
                        count += 3 * x;
                    } else if (b < c / 2) {
                        count += 3 * b;
                        b -= b;
                    }
                }
                if (a > 0 && b > 1) {
                    if (a > b / 2) {
                        int y = b / 2;
                        a -= y;
                        count += 3 * y;
                    } else if (a < b / 2) {
                        count += 3 * a;
                    }
                }
            }
            System.out.println(count);
        }
    }
}
