import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = Integer.parseInt(s.nextLine());

        while (t-- > 0) {
            String in = s.nextLine();
            String[] arr = in.split(" ");

            int a = Integer.parseInt(arr[0]);
            int b = Integer.parseInt(arr[1]);
            int c = Integer.parseInt(arr[1]);

            int totalSelected = 0;
            int maxStones = findMaxStones(a, b, c, totalSelected);
            System.out.println(maxStones);
        }
    }

    public static int findMaxStones(int a, int b, int c, int total) {

        int maxA = 0, maxB = 0;
        if (a >= 1 && b >= 2) {
            maxA = findMaxStones(a - 1, b - 2, c, total + 3);
        }
        if (b >= 1 && c >= 2) {
            maxB = findMaxStones(a, b - 1, c - 2, total + 3);
        }

        return Math.max(Math.max(total, maxA), maxB);
    }
}
