t = int(input())
for i in range(t):
  a,b,c = map(int,input().split())
  cnt=0
  x1 = a+b
  x2 = b+c
  #print(x1,x2)
  if x1>x2:
    while(a>=1 and b>=2):
      a=a-1
      b=b-2
      cnt = cnt+3
    #print(a,b,c,1111)
    while(b>=1 and c>=2):
      b=b-1
      c=c-2
      cnt = cnt+3
    #print(a,b,c,22222222)
  elif x1<=x2:
    while(b>=1 and c>=2):
      b=b-1
      c=c-2
      #print(b,c)
      cnt = cnt+3
    while(a>=1 and b>=2):
      a=a-1
      b=b-2
      #print(a,b)
      cnt = cnt+3
  print(cnt)
