def Stones():
    T=int(input())
    S=0
    for x in range(T):
        A, B, C = map(int, input().split())
        data=[A,B,C]
        cnt = 0
        Flage = 0
        while True:
            if data[cnt%3]>0 and data[(cnt+1)%3]>1:
                S +=3
                data[cnt%3]=data[cnt%3]-1
                data[(cnt + 1) % 3] = data[(cnt+1)%3] -2
                cnt += 1
                Flage =0
            else:
                Flage +=1
            if Flage == 2:
                print(S)
                S = 0
                break

Stones()