for x in range(int(input())):
	l=list(map(int,input().split()))
	stones=0
	while (l[1]>=1 and l[-1]>=2):
		l[1]-=1
		l[-1]-=2
		stones+=3
	while (l[0]>=1 and l[1]>=2):
		l[0]-=1
		l[1]-=2
		stones+=3
	print(stones)