t = int(input())
testcases = [[int(x) for x in input().split()] for x in range(t)]

for testcase in testcases:
    biggest = testcase.index(max(testcase[1:]))
    if biggest == 1:
        most = testcase[1]//2
        most = testcase[0] if most > testcase[0] else most
        left = testcase[1] - (2*most)
        nmost = testcase[2]//2
        nmost = left if most > left else nmost

        print((nmost+most)*3)
    elif biggest == 2:
        most = testcase[2]//2
        most = testcase[1] if most > testcase[1] else most
        left = testcase[2] - (2*most)
        nmost = testcase[1]//2
        nmost = left if most > left else nmost

        print((nmost+most)*3)
