import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
List<Block> blocks = null;
public void inital(){
Scanner cin = new Scanner(System.in);
int n;
int m = 1;
while((n = cin.nextInt()) != 0){
blocks = new ArrayList<Block>();
for(int i = 0; i < n; i++){
int x = cin.nextInt();
int y = cin.nextInt();
int h = cin.nextInt();
if(x == y){
//x == y == z一种
if(y == h)
blocks.add(new Block(x, y, h, h));
//x == y != z三种
else {
blocks.add(new Block(x, x, h, h));
blocks.add(new Block(h, x, x, x));
blocks.add(new Block(x, h, x, x));
}
}
else{
//x == h != y三种
if(x == h){
blocks.add(new Block(x, x, y, y));
blocks.add(new Block(y, x, x, x));
blocks.add(new Block(x, y, x, x));
}
else if(y == h ){
blocks.add(new Block(x, y, y, y));
blocks.add(new Block(y, y, x, x));
blocks.add(new Block(y, x, y, y));
}
//x != y != h
else{
blocks.add(new Block(x, y, h, h));
blocks.add(new Block(x, h, y, y));
blocks.add(new Block(y, x, h, h));
blocks.add(new Block(y, h, x, x));
blocks.add(new Block(h, x, y, y));
blocks.add(new Block(h, y, x, x));
}
}
}
sort(blocks);
int maxH = 0;
for(int i = 0; i < blocks.size(); i++){
for(int j = 0; j < i; j++){
if(blocks.get(j).x < blocks.get(i).x && blocks.get(j).y < blocks.get(i).y){
blocks.get(i).dp = max((blocks.get(i).h + blocks.get(j).dp), blocks.get(i).dp);
}
maxH = max(blocks.get(i).dp, maxH);
}
}
System.out.println("Case " + (m++) + ": maximum height = " + maxH);
}
cin.close();
}
public int max(int a, int b){
return a > b ? a : b;
}
public void sort(List<Block> blocks){
boolean exchange;
for(int i = blocks.size() - 1; i > 0; i--){
exchange = false;
for(int j = 0; j < i; j++){
if(blocks.get(j).x > blocks.get(j+1).x ){
Block temp = blocks.get(j);
blocks.set(j, blocks.get(j+1));
blocks.set(j+1, temp);
exchange = true;
}
else if(blocks.get(j).x == blocks.get(j+1).x){
if(blocks.get(j).y > blocks.get(j+1).y){
Block temp = blocks.get(j);
blocks.set(j, blocks.get(j+1));
blocks.set(j+1, temp);
exchange = true;
}
}
}
if(!exchange){
return;
}
}
}
public static void main(String[] args) {
new Main().inital();
}
class Block{
public int x;
public int y;
public int h;
public int dp;//dp指的是该块箱子放在最下面时此方案的最大的高度。
public Block(int x, int y, int h, int dp) {
this.x = x;
this.y = y;
this.h = h;
this.dp = dp;
}
}
}