import java.io.*;
 
public class A1236Stones {
 
    public static void main(String[] args) throws IOException {
 
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
 
        int t = Integer.parseInt(in.readLine());
        while (t-- != 0) {
            String[] s = in.readLine().split(" ");
            int a = Integer.parseInt(s[0]);
            int b = Integer.parseInt(s[1]);
            int c = Integer.parseInt(s[2]);
            out.write(solution(a,b,c) + "\n");
        }
        out.flush();
    }
 
    public static int solution(int a, int b, int c){
            int count = 0;
            int temp = c/2;
            for (int i = 0;; i++) {
                //if ((b<1 || c<2)) break;
                temp -= i;
                if (b - temp >= 0) {
                    c -= 2 * temp;
                    b -= temp;
                    count += 3 * temp;
 
                }
                if ((a<1 || b<2)) break;
                temp = b/2;
                if (a - temp >= 0){
                    b -= 2*temp;
                    a -= temp;
                    count += 3*temp;
                }
 
            }
 
        return count;
    }
}