#include<iostream>
#include<cstring>

using namespace std;

int n, ans, box[10][3];
bool seen[10];

void recur(int k, int rot, int num) {
	for(int i=0; i<n; i++) {
		if(seen[i]) continue;
		seen[i] = true;
		for(int j=0; j<3; j++) {
			int x,y;
			if(j==0) x=box[i][1], y=box[i][2];
			if(j==1) x=box[i][0], y=box[i][2];
			if(j==2) x=box[i][0], y=box[i][1];
			int x2,y2;
			if(rot==0) x2=box[k][1], y2=box[k][2];
			if(rot==1) x2=box[k][0], y2=box[k][2];
			if(rot==2) x2=box[k][0], y2=box[k][1];
			if((x>=x2 && y>=y2) || (x>=y2 && y>=x2)) {
				ans = max(ans, num+1);
				recur(i,j,num+1);
			}

		}
		seen[i] = false;
	}
}

int main(void) {
	int ca=0;
	while(cin>>n) {
		if(n==0) break;
		for(int i=0; i<n; i++) {
			for(int j=0; j<3; j++) {
				cin >> box[i][j];
			}
		}
		ans = 1;
		memset(seen, 0, sizeof seen);
		for(int i=0; i<n; i++) {
			seen[i] = true;
			for(int j=0; j<3; j++) {
				recur(i,j,1);
			}
			seen[i] = false;
		}
		cout << "Case " << ++ca << ": ";
		cout << ans << endl;
	}
	return 0;
}