number = input()
counter = 0
array = []
for i in range(int(number)):
    x,y,z = input().split()
    while int(y) > 0 and int(z) >= 2:
        y = int(y) - 1
        z = int(z) - 2
        counter = counter + 3
    while int(x) > 0 and int(y) >= 2:
        x = int(x) - 1
        y = int(y) - 2
        counter = counter + 3
    array.append(counter)
    counter = 0
for i in range(int(number)):
    print(array[i])
