import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class MainA {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int test_case = Integer.parseInt(br.readLine());
		for (int t = 1; t <= test_case; t++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			int ans = 0;
			while ((a >= 1 && b >= 2) || (b >= 1 && c >= 2)) {
				if (a <= b && b <= c) {
					b--;
					c -= 2;
				} else if (a <= c && c <= b) {
					b--;
					c -= 2;
				}else if(b <= a && a<=c) {
					b--;
					c -= 2;
				}else if(c <= a && a<= b) {
					a--;
					b-= 2;
				}else if(b <=c && c<=a) {
					b--;
					c-=2;
				}else if(c <= b && b<=a) {
					b--;
					c-=2;
				}
				ans +=3;
			}
			System.out.println(ans);
		}
	}

}
