# cook your dish here
n=int(input())
for i in range(n):
    a,b,c=map(int,input().split())
    count=0
    while True :
        if a>=0 and b>=0 and c>=0:
            if a>=1 and b>=2:
                a=a-1
                b=b-2
                count+=1
            if b>=1 and c>=2:
                b=b-1
                c=c-2
                count+=1
            else:
                break
        else:
            break

    print(count*3) 