#include<stdio.h>
#include<stdlib.h>
int max(long long *a){int cpt1=0;

	
		while(a[1]>=2){
			if(a[2]>=a[1]){cpt1+=3;a[1]--;a[2]-=2;}
			else{if(a[0]>=1){
			cpt1+=3;a[0]--;a[1]-=2;}}
		}
		while(a[1]>0&&a[2]>=2){
			cpt1+=3;a[1]--;a[2]-=2;
		}
		
	return(cpt1);
}
main(){
	
long long t,i;long long j,r;
	scanf("%d",&t);
	while(t>=0&&t<=100){
		
	
	long long **a=malloc(t*sizeof(long long*));
	for(j=0;j<t;j++){
	a[j]=malloc(3*sizeof(long long));
	}
	int flag=1;
	for(i=0;i<t;i++){
		for(j=0;j<3;j++){
			scanf("%d",&a[i][j]);
			if(a[i][j]<0||a[i][j]>100){flag=0;
			}
		
		}
	}
	while(flag==1){
		for(i=0;i<t;i++){
		r=max((a[i]));
		printf("%d\n",r);
	}
	}
	
}
}
