#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
#define MAXN 30*3+5
using namespace std;
struct Box {
int x,y,z;
Box() = default;
Box(int x, int y, int z):x(x),y(y),z(z){}
bool operator < (const Box &b) const {
return this->x<b.x && this->y<b.y;
}
};
int n;
int dp[MAXN];
vector<int> E[MAXN];
queue<int> q;
int cnt = 0;
inline void init()
{
for (auto &v : E) v.clear();
while(!q.empty()) q.pop();
++cnt;
}
int main()
{
int a[3];
while(~scanf("%d",&n) && n)
{
init();
Box box[MAXN];
for(int i=0; i<n; ++i)
{
scanf("%d%d%d",&a[0],&a[1],&a[2]);
sort(a,a+3);
box[3*i] = Box(a[0],a[1],a[2]);
box[3*i+1] = Box(a[0],a[2],a[1]);
box[3*i+2] = Box(a[1],a[2],a[0]);
}
for(int i=0; i<3*n; ++i)
for(int j=0; j<3*n; ++j)
if (box[i]<box[j])
E[i].push_back(j);
int maxx = -INF;
for (int i=0; i<3*n; ++i)
{
memset(dp, 0, sizeof(dp));
dp[i] = box[i].z;
q.push(i);
while(!q.empty())
{
int cur = q.front();
q.pop();
for (auto &e : E[cur])
{
if (dp[e] < dp[cur]+box[e].z)
{
dp[e] = dp[cur]+box[e].z;
q.push(e);
}
}
}
for (int i=0; i<3*n; ++i)
maxx = max(maxx, dp[i]);
}
printf("Case %d: maximum height = %d\n",cnt ,maxx);
}
return 0;
}