#include <iostream>
#include <cstring>

using namespace std;

int n;
int dim[10][3];
bool seen[10];
int dfs(int cx, int cy, int cnt) {
    if (cnt == n) return n;
    int ans = cnt;
    for (int i = 0; i < n; i++) {
        if (seen[i]) continue;
        seen[i] = true;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                if (dim[i][j] <= cx && dim[i][k] <= cy) {
                    ans = max(ans, dfs(dim[i][j], dim[i][k], cnt+1));
                }
            }
        }
        seen[i] = false;
    }
    return ans;
}
int main() {
    int csnum = 1;
    cin >> n;
    while (n != 0) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                cin >> dim[i][j];
            }
        }
        memset(seen, 0, sizeof seen);
        cout << "Case " << csnum << ": " << dfs(1000, 1000, 0) << endl;
        cin >> n;
        csnum++;
    }
}