
/*
ID: grifync1
LANG: JAVA
PROG: stones
*/

//lil lil peezy
import java.util.*;
import java.io.*;

public class stones {
	public static int conv(String s) {
		return Integer.parseInt(s);
	}

	public static int max(int a, int b) {
		return Math.max(a, b);
	}

	public static int min(int a, int b) {
		return Math.min(a, b);
	}

	public static void main(String[] args) throws IOException {
		//BufferedReader in = new BufferedReader(new FileReader("stones.in"));
		//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("stones.out")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		int len = conv(in.readLine());
		for(int i=0; i<len; i++) {
			StringTokenizer st= new StringTokenizer(in.readLine());
			int[] piles = new int[3];
			for(int p=0; p<3; p++) {
				piles[p]=conv(st.nextToken());
			}
			int stones = 0;
			while(piles[1]>2 && piles[2]>0) {
				piles[1]-=1;
				piles[2]-=2;
				stones+=3;
			}
			if(piles[0]>1 && piles[1]>2) {
				while(piles[0]>0 && piles[1]>0) {
					piles[0]-=1;
					piles[1]-=2;
					stones+=3;
				}
			}
			System.out.println(stones+3);
		}
		in.close();
		out.close();
	}

}
