n=int(input())
for i in range(n):
    a,b,c=map(int,input().split())
    t=1
    s=0
    while(t>0):
        if(b-1>=0 and c-2>=0):
            b=b-1
            c=c-2
            s=s+3
        else:
            t=-1
    t=1
    while(t>0):
        if(a-1>=0 and b-2>=0):
            b=b-2
            a=a-1
            s=s+3
        else:
            t=-1
    print(s)