n=int(input())
l=[]
for i in range(n):
   count=0

   k=list(map(int,input().split()))
   if k[1]==0 or k[1]==0 or k[2]==0:
      l.append(0)
   elif k[1]==1 and k[2]==1:
      l.append(0)
   else:
      while k[2]>1 and k[1]>=1:
         count=count+3
         k[2]=k[2]-2
         k[1]=k[1]-1
      while k[1]>1 and k[0]>=1:
         count=count+3
         k[1]=k[1]-2
         k[0]=k[0]-1
      l.append(count)
for i in l:
   print(i)


