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