def counts(x,y,balls_count):
	q=y//2
	if x>=q:
		balls_count+=q*3
		x-=q
	else:
		balls_count+=x*3
		x=0
	return x,y,balls_count
 
 
t=int(input())
while(t):
	balls=[int(i) for i in input().split()]
	balls_count=0
	a,b,c=balls
	if b==0:
		print(0)
	else:
		b,c,balls_count=counts(b,c,balls_count)
		a,b,balls_count=counts(a,b,balls_count)
		print(balls_count)
	t-=1 