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

int n;
int case_num;
int used[10];
vector<vector<int>> boxes;

int solution(int w, int h, int count) {
        int best = count;
        for (int i = 0; i < n; i++) {
                if (!used[i]) {
                        used[i] = 1;
                        for (int j = 0; j < 3; j++) {
                                for (int k = 0; k < 3; k++) {
                                        if (j != k && boxes[i][j] <= w && boxes[i][k] <= h) {
                                                best = max(best, solution(boxes[i][j], boxes[i][k], count+1));
                                        }
                                }
                        }
                        used[i] = 0;
                }
        }
        return best;
}

int main() {
        while (cin >> n && n) {
                memset(used, 0, 10);
                boxes.clear();
                int dim;
                for (int i = 0; i < n; i++) {
                        vector<int> box;
                        for (int j = 0; j < 3; j++) {
                                cin >> dim;
                                box.push_back(dim);
                        }
                        boxes.push_back(box);
                }
                cout << "Case " << ++case_num << ": ";
                cout << solution(100, 100, 0) << '\n';
        }
        return 0;
}