import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	static int[][][] dp;
	static int best;
	static void dp(int box, int face, int visited, ArrayList<int[][]> boxes, int n){
		for(int i = 0; i < n; i++){
			if(((1<<i)&visited) == 0){
				int s = boxes.get(box)[face][0];
				int l = boxes.get(box)[face][1];
				if(boxes.get(i)[2][0] <= s && boxes.get(i)[2][1] <= l){
					dp[i][2][visited + (1<<i)] = Math.max(dp[i][2][visited + (1<<i)], dp[box][face][visited] + 1);
					best = Math.max(best, dp[i][2][visited + (1<<i)]);
					//System.out.println(dp[i][2][visited + (1<<i)]);
					dp(i,2,visited + (1<<i), boxes,n);
				}
				if(boxes.get(i)[1][0] <= s && boxes.get(i)[1][1] <= l){
					dp[i][1][visited + (1<<i)] = Math.max(dp[i][1][visited + (1<<i)], dp[box][face][visited] + 1);
					best = Math.max(best, dp[i][1][visited + (1<<i)]);
					dp(i,1,visited + (1<<i), boxes,n);
				}
				if(boxes.get(i)[0][0] <= s && boxes.get(i)[0][1] <= l){
					dp[i][0][visited + (1<<i)] = Math.max(dp[i][0][visited + (1<<i)], dp[box][face][visited] + 1);
					best = Math.max(best, dp[i][0][visited + (1<<i)]);
					dp(i,0,visited + (1<<i), boxes,n);
				}
			}
		}
		return;
		
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		int cases = 1;
		while(n != 0){
			ArrayList<int[][]> boxes = new ArrayList<int[][]>();
			for(int i = 0; i < n; i++){
				String[] in1 = in.readLine().split(" ");
				best = 0;
				int[] temp = new int[3];
				temp[0] = Integer.parseInt(in1[0]);
				temp[1] = Integer.parseInt(in1[1]);
				temp[2] = Integer.parseInt(in1[2]);
				Arrays.sort(temp);
				dp = new int[n][3][1<<n];
				int[][] toAdd = new int[3][2];
				toAdd[0][0] = temp[0];
				toAdd[0][1] = temp[1];
				toAdd[1][0] = temp[0];
				toAdd[1][1] = temp[2];
				toAdd[2][0] = temp[1];
				toAdd[2][1] = temp[2];
				boxes.add(toAdd);
			}
			
			for(int i = 0; i < n; i++){
				dp[i][2][1<<i] = 1;
				dp[i][1][1<<i] = 1;
				dp[i][0][1<<i] = 1;
				dp(i,2,1<<i,boxes,n);
				dp(i,1,1<<i,boxes,n);
				dp(i,0,1<<i,boxes,n);
				
			}
			
			n = Integer.parseInt(in.readLine());
			System.out.println("Case " + cases + ": " + best);
			cases++;
		}
	}

}