Babs’ Box Boutique

Time limit1sMemory limit128 MB

Problem

Babs sells boxes, and lots of them. All her boxes are rectangular but come in many different sizes. Babs wants to create an eye-catching display by stacking, one on top of another, as many boxes as she can outside her store. For neatness and stability she always keeps the sides of the boxes parallel, and she never puts a box on top of another if the top box sticks out over the bottom one. For example, a box with a 5-by-10 base cannot be placed on a box with a 12-by-4 base.

Each box has three dimensions, and Babs may orient a box any way she likes. Thus a 5-by-10-by-12 box may be stacked so that its base is 5-by-10, 5-by-12, or 10-by-12.

For example, if Babs currently has 4 boxes of dimensions 2-2-9, 6-5-5, 1-4-9, and 3-1-1, she can stack up to 3 of them but not all four. (For instance, the third box, then the first box, then the last box, each suitably oriented; alternatively, the second box could replace the third as the bottom box.)

Babs' stock rotates, so the boxes she displays change frequently, and it is too much for her to work out by hand. Your job is to find the greatest number of boxes Babs can stack from her current inventory. Babs has no more than 10 differently sized boxes and uses at most one box of each size in her display.

Input

The input contains several test cases. Each test case begins with a line holding a positive integer $n$ ($n \le 10$), the number of boxes. Each of the next $n$ lines contains three positive integers giving the dimensions of one box. No two boxes have identical dimensions, and no dimension exceeds $20$. A line containing a single $0$ follows the last test case.

Output

For each test case, print a line of the form Case k: m, where $k$ is the test case number (starting from $1$) and $m$ is the maximum number of boxes Babs can stack.