t = int(input(''))

temp=''
while t>0:
    Allheaps = input('')
    temp = temp + str(Allheaps)
    t = t-1

heaps = ''    
for i in temp:
    
    if i != ' ':
        heaps = heaps + i
  
    if len(heaps) == 3:
      
        a = heaps[0] 
        b = heaps[1]
        c = heaps[2]
        
        stones = 0
        
        while (int(a)>0 and int(b)>1) or (int(b)>0 and int(c)>1):
                       
            if int(b)>0 and int(c)>1:
                stones = stones + 3
                b = int(b) -1
                c = int(c) -2
           
            if int(a)>0 and int(b)>1:
                stones = stones + 3
                a = int(a) - 1
                b = int(b) - 2
      
        if stones > 9:
            stones = 9
            
        print(stones)
        heaps = ''