t=int(input())
for i in range(t):
    a, b, c=[x for x in map(int, input().split())]
    res=0
    for i in range(a+1):
        for j in range(c//2+1):
            if i+j <= (a+b+c)//3 and 2*i+j <=b:
                res=max(res, (i+j)*3)
    print(res)