import java.util.*;
import java.lang.Math;
public class CA{

public static void main(String [] args){
	Scanner obj=new Scanner (System.in);
	    int q=obj.nextInt();
	     int req=0;
	    while(q-->0)
	    {   req=0;
	    	int a=obj.nextInt();
	    	int b=obj.nextInt();
	    	int c=obj.nextInt();
	    	if(b==0)
	    		System.out.println(0);
	    	else{
	    	 if(c==Math.max(Math.max(a,b),c))
	    	 {
	    	 	while(b>0&&c>=2){
	        	b=b-1;
	            c=c-2;
	            req=req+3;
	        }
	        while(a>0&&b>=2){
	        	a=a-1;
	        	b=b-2;
	        	req=req+3;
	    	 }
                 }
	        else{
	        while(a>0&&b>=2){
	        	a=a-1;
	        	b=b-2;
	        	req=req+3;

	        }
	        while(b>0&&c>=2){
	        	b=b-1;
	            c=c-2;
	            req=req+3;

	    	}}
	    	System.out.println(req);
           }

	    }
	  }
	}
    
