// Arup Guha
// 7/20/2013
// Solution to 2012 East Central Regional Problem A: Babs' Box Boutique
import java.util.*;

public class a {

	public static int n;
	public static int[][] boxes;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		int loop = 1;

		// Go through each case.
		while (n != 0) {

			// Get all boxes.
			boxes = new int[n][3];
			for (int i=0; i<n; i++) {
				for (int j=0; j<3; j++)
					boxes[i][j] = stdin.nextInt();
				Arrays.sort(boxes[i]);
			}

			// Solve and print.
			System.out.println("Case "+loop+": "+solve());

			// Go to next case.
			n = stdin.nextInt();
			loop++;
		}
	}

	// Wrapper function.
	public static int solve() {
		int[] perm = new int[n];
		boolean[] used = new boolean[n];
		return solveRec(perm, used, 0);
	}

	// Tries all perms that start with perm[0..k-1].
	public static int solveRec(int[] perm, boolean[] used, int k) {

		// Base case, ready to evaluate permutation.
		if (k == n) {
			return getBest(perm);
		}

		// Recursively try each possible unused item in position k.
		int best = 1;
		for (int i=0; i<used.length; i++) {
			if (!used[i]) {
				perm[k] = i;
				used[i] = true;
				int cur = solveRec(perm, used, k+1);
				if (cur > best) best = cur;
				used[i] = false;
			}
		}

		return best;
	}

	// Get the best answer with the boxes in this order, perm[0] on bottom.
	public static int getBest(int[] perm) {

		int cnt = 1;

		// Make X >= Y...
		int curX = boxes[perm[0]][2], curY = boxes[perm[0]][1];

		// Try greedily fitting these boxes in order.
		for (int i=1; i<n; i++)	{

			int[] next = boxes[perm[i]];

			// Biggest dimension works.
			if (next[2] <= curX) {

				// Then get the next best fit.
				if (next[1] <= curY) {
					cnt++;
					curX = next[2]; curY = next[1];
				}
				else if (next[0] <= curY) {
					cnt++;
					curX = next[2]; curY = next[0];
				}
			}

			// Can only match the two smallest dimensions.
			else if (next[1] <= curX && next[0] <= curY) {
				cnt++;
				curX = next[1]; curY = next[0];
			}
		}

		return cnt;
	}
}