import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		while(sc.hasNext()){
			int b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
			int e = 0, sum = 0;
			if(b >= 1 && c > 2 && d >= 2){
				e = Math.min(c, d / 2);
				if((c - e) == 0){
					sum = sum + (e - 1) * 3;
				}else{
					sum = sum + e * 3;
				}
				
			}
			if(b >= 1 && c >= 2){
				e = Math.min(b, (c - e) / 2);
				sum = sum + e * 3;
			}
			System.out.println(sum);
			
			
		}
		
	}
}
		  	 		   	  			 		 	     				