import java.util.*;

public class Solution {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] results = new int[n];
		for(int i = 0; i < n; i++) {
			results[i] = testCase(scanner);
		}
		for(int i = 0; i < n; i++) {
			System.out.println(results[i]);
		}
		//System.out.println(testCase(scanner));
	}
	
	private static int testCase(Scanner scanner) {
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		//System.out.println("a = " + a + ", b = " + b + ", c = " + c);

		int p1 = a;
		int p2 = c/2;
		
		int diff = 0;
		//System.out.println("p1 = " + p1 + ", p2 = " + p2 + ", " + expr(p1, p2));
		int max = 0;
		while(expr(p1, p2) > b) {
			diff++;
			//System.out.println("diff = " + diff);
			for(int i = 0; i <= diff; i++) {
				p1 = a - i;
				p2 = (c/2) - (diff - i);
				//System.out.println("p1 = " + p1 + ", p2 = " + p2 + ", " + expr(p1, p2));
				if(p1 >= 0 && p2 >= 0 && expr(p1, p2) <= b) {
					max = Math.max(max, (p1 + p2));
				}
			}
		}
	
		
		return 3*max;
	}
	
	private static int expr(int p1, int p2) {
		return 2*p1 + p2;
	}
}