#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef tuple<int,int,int> tii;

#define endl '\n'

vector<vector<pii>> boxes;

int dfs(set<int> remain, pii base) {
	if (remain.size() == 0) return 1;
	int mx = 0;
	for (int index : remain) {
		set<int> remain2 = remain;
		remain2.erase(index);
		vector<pii> box = boxes[index];
		for (pii base2 : box) {
			if ( (base.first >= base2.first && base.second >= base2.second) ||
				 (base.second >= base2.first && base.first >= base2.second)) {
				mx = max(mx, dfs(remain2, { base2.first, base2.second }));
			}
		}
	}
	return mx+1;
}

int main() {
	ios::sync_with_stdio(0);
	int n;
	int T = 1;
	while(cin >> n && n) {
		boxes.clear();
		for (int i=0; i<n; i++) {
			int x,y,z; cin >> x >> y >> z;
			vector<pii> curr;
			curr.push_back({x,y});
			curr.push_back({x,z});
			curr.push_back({y,z});
			boxes.push_back(curr);
		}
		set<int> all;
		for (int i=0; i<n; i++) {
			all.insert(i);
		}
		int ans = dfs(all, {100, 100});
		cout << "Case " << T << ": " << ans-1 << endl;
		T++;
	}
	return 0;
}