t = int(input())
for _ in range(t):
    a, b, c = map(int, input().split())
    k0 = min(a, b // 2)
    l0 = min(b - k0 * 2, c // 2)
    k1 = min(b, c // 2)
    l1 = min(a, (b - k1) // 2)
    print(max(k0 + l0, k1 + l1) * 3)