def stones(x,y,s):
    if(x==0 or y==0):
        return(s+0,x);
    else:
        while(x>0 and y>1):
           x-=1
           y-=2
           s+=3
        return(s,x)

t=int(input())
while(t>0):
    sum=0
    lst=list(map(int,input().split()))[0:3]
    final,b=stones(lst[1],lst[2],0)
    sum,c=stones(lst[0],b,final)
    print(sum)
    t=t-1














