def mp():
    return map(int, input().split())

t = int(input())
for tt in range(t):
    a, b, c = mp()
    cnt = 0
    while (a >= 1 and b >= 2) or (b >= 1 and c >= 2):
        if c >= 2:
            b -= 1
            c -= 2
        else:
            a -= 1
            b -= 2
        cnt += 3
    print(cnt)