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