import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Stones
{
    public static void main( String [] args )
    {
        Scanner input = new Scanner( System.in );
        List<Integer> saveCounter = new ArrayList<>();

        int t = input.nextInt();

        for( int i = 0; i < t; i++ )
        {
            int a = input.nextInt(), b = input.nextInt(), c  = input.nextInt(), counter = 0;

            saveCounter.clear();

            if( a != 0 )
            {
                while( (c >= b && c >= 2 && b >= 1) || (b >= 2 && a >= 1) )
                {
                    if( c >= b )
                    {
                        b -= 1; counter += 1;
                        c -= 2; counter += 2;

                        saveCounter.add( counter );
                    }
                    else if( a >= 1 )
                    {
                        a -= 1; counter += 1;
                        b -= 2; counter += 2;


                        saveCounter.add( counter );
                    }
                }
            }
            else
            {
                while( c > 0 && b > 0 )
                {
                    b -= 1; counter += 1;
                    c -= 2; counter += 2;

                    saveCounter.add( counter );

                    //if( b == 0 || c == 0 )
                        //break;
                }
            }

            Collections.sort( saveCounter );

            if( saveCounter.size() > 0 )
                System.out.println( saveCounter.get( saveCounter.size() - 1 ) );
            else
                System.out.println( 0 );
        }
    }
}