 var t =readline().split("").map(function(x) { return parseInt(x); });
     
    for(var _=0;_<t[0];_++)
    {
        var Heap = readline().split(" ").map(function(x) { return parseInt(x); });
        var _Heap = Heap.slice();
 
        var count = 0;
        var _count;
 
       // print(Heap);
        while(Heap[2]>1&&Heap[1]>0)
        {
            count+=3;
            Heap[2]-=2;
            Heap[1]-=1;
           // print(`1: ${Heap} ${_Heap}`)
        }
        while(Heap[1]>1&&Heap[0]>0)
        {
            count+=3;
            Heap[1]-=2;
            Heap[0]-=1;
            //print(`2: ${Heap}`)
        }
        //print(`${count}`)
        _count = count;
        count=0;
        Heap=_Heap;

        
        while(Heap[1]>1&&Heap[0]>0)
        {
            count+=3;
            Heap[1]-=2;
            Heap[0]-=1;
            //print(`3: ${Heap}`)
        }

        while(Heap[2]>0&&Heap[1]>1)
        {
            count+=3;
            Heap[2]-=2;
            Heap[1]-=1;
           // print(`4: ${Heap}`)
        }
       // print(`${count}`)
 
        if(count<_count)count = _count;
        print (count);

    }