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 stone = 0;
            if (a > c) {
                while (a >= 1 & b >= 2) {
                    a = a - 1;
                    b = b - 2;
                    stone = stone + 3;
                }
                if (b >= 1 & c >= 2) {
                    b = b - 1;
                    c = c - 2;
                    stone = stone + 3;
                }
            }
            if (c > a) {
                while (b >= 1 & c >= 2) {
                    b = b - 1;
                    c = c - 2;
                    stone = stone + 3;
                }
                if (a >= 1 & b >= 2) {
                    a = a - 1;
                    b = b - 2;
                    stone = stone + 3;
                }
            }
            System.out.println(stone);
        }
    }
}