t = int(input())

def bandc(b,c,output):
	c-=2
	b-=1
	output+=3
	if c >= 2 and b>=1:
		bandc(b,c,output)
	return b,output

def aandb(a,b,output):
	a-=1
	b-=2
	output+=3
	if a >=1 and b >= 2:
		aandb(a,b,output)
	return output

for x in range(t):
	a,b,c = list(map(int, input().split()))
	output = 0
	if b >= 1 and c >=2:
		b,output = bandc(b,c,output)
	if a >= 1 and b >= 2:
		output = aandb(a,b,output)
	print(output)
