def take(a, b, answer):        
    return a-1, b-2, answer+3
 
k = int(input())

for i in range(0,k):
    answer = 0
    a, b, c = map(int, input().split())
    while c >= 2 and b >= 1:
        b, c, answer = take(b, c, answer)
    while b >= 2 and a >= 1:
        a, b, answer = take(a, b, answer)
    print(answer)