a=int(input())
r=0
x=list()
while r<a:
    d=0
    c=[int(c) for c in input().split()]
    while True:
        if c[2]>=2 and c[1]>=1:
            c[2]=c[2]-2
            c[1]=c[1]-1
            d=d+3
        elif c[1]>=2 and c[0]>=1:
            c[1]=c[1]-2
            c[0]=c[0]-1
            d=d+3
        else:
            break    
    r=r+1
    x.append(d)
r=0
while r<a:
    print(x[r])
    r=r+1
