n = int(input())
mli = []
for i in range(n):
    tli = []
    tli = list(map(int, input().split(" ")))
    mli.append(tli)
for i in range(n):
    init = 0
    ind = mli[i].index(max(mli[i]))
    if(ind == 2):
        while(mli[i][1] >= 1 and mli[i][2] >= 2):
            init = init + 3
            mli[i][1] = mli[i][1] - 1
            mli[i][2] = mli[i][2] - 2
        while(mli[i][0] >= 1 and mli[i][1] >= 2):
            init = init + 3
            mli[i][0] = mli[i][0] - 1
            mli[i][1] = mli[i][1] - 2
    elif(ind == 1 or ind == 0):
        while(mli[i][0] >= 1 and mli[i][1] >= 2):
            init = init + 3
            mli[i][0] = mli[i][0] - 1
            mli[i][1] = mli[i][1] - 2
        while(mli[i][1] >= 1 and mli[i][2] >= 2):
            init = init + 3
            mli[i][1] = mli[i][1] - 1
            mli[i][2] = mli[i][2] - 2
    print(init)
    init = 0
