import java.util.*;

public class Practice1{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- > 0){
			int[] arr = new int[3];
			for(int i = 0; i < 3; i++){
				arr[i] = sc.nextInt();
			}
			int ans = max_stone(arr);
			System.out.println(ans);
		}
		
	}
	
	public static int max_stone(int[] arr){
		int a = arr[0];
		int b = arr[1];
		int c = arr[2];
		int count = 0;
		while(true){
			if((a > 0 && b > 1) || (b > 0 && c > 1)){
			int mx = Math.max(b,c);
			if(mx == b && b >= 2 && mx != c){
				a = a - 1;
				b = b - 2;
				count += 3;;
			}
			if(mx == c && c >= 2){
				b = b - 1;
				c = c - 2;
				count += 3;
				//System.out.println("c is " + c);
			}
			}else
				break;
		}
		return count;
	}

	}