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

    print(max(count,count2)*3) 