//* Problem  : B - Babylon
//* Contest  : UzhNU Local
//* Origin   : Ulm-1996
//* Type     : Solution
//* Date     : 2008.02.04
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algoritm : DP O(n^2)

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define MIN(a,b)(a<b?a:b)
#define MAX(a,b)(a>b?a:b)

int n;

int a[100][3], res;
int w[100];

int cmp_f(const void *a, const void *b)
{
	int k = ((int*)a)[0] - ((int*)b)[0];
	if (k) return k;
	k = ((int*)a)[1] - ((int*)b)[1];
	return k;
}

int main()
{
	int nt = 0;
	while (1)
	{
		scanf("%d", &n); if (!n) break;
		nt++;
		printf("Case %d: maximum height = ", nt);
		int i, x, y, z, j;
		for (i = 0; i < n; i++)
		{
			scanf("%d%d%d", &x, &y, &z);
			a[3*i][0] = MIN(x, y);
			a[3*i][1] = MAX(x, y);
			a[3*i][2] = z;
			a[3*i+1][0] = MIN(z, y);
			a[3*i+1][1] = MAX(z, y);
			a[3*i+1][2] = x;
			a[3*i+2][0] = MIN(x, z);
			a[3*i+2][1] = MAX(x, z);
			a[3*i+2][2] = y;
		}
		qsort(a, 3*n, sizeof(a[0]), cmp_f);
		res = 0;
		for (i = 0; i < 3*n; i++)
		{
			w[i] = 0;
			for (j = 0; j < i; j++)
				if (a[i][0] > a[j][0] && a[i][1] > a[j][1] && w[j] > w[i])
					w[i] = w[j];
			w[i] += a[i][2];
			if (w[i] > res)
				res = w[i];
		}
		printf("%d\n", res);
	}
	return 0;
}