import java.io.*;

public class StonesA {
    static int solution(int[] arr){
        int count = 0;
        while((arr[0]>=1 && arr[1]>=2) || (arr[1]>=1 && arr[2]>=2)) {
            if (arr[0] < arr[1]) {
                arr[0] -=1;
                arr[1] -=2;
                count+=3;
            } else{
                arr[1]-=1;
                arr[2]-=2;
                count+=3;
            }
        }
        return count;
    }

    public static void main(String[] args) throws IOException {
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(bufferedReader.readLine());

        for(int i=0; i<t; i++){
            String[] s = bufferedReader.readLine().split(" ");
            int[] arr = new int[3];
            for(int j=0; j<3; j++){
                arr[j] = Integer.parseInt(s[j]);
            }
            bufferedWriter.write(String.valueOf(solution(arr)) + "\n");
        }
        bufferedWriter.close();

    }
}