Nested Shrubbery Boxes

No attempts yetTime limit1sMemory limit128 MB

Problem

Every time Roger the Shrubber finishes a job planting a shrubbery, he hauls a cartload of empty planting boxes back home. A planting box here is a wooden box with one open side.

You are given nn planting boxes. Find the largest number of boxes you can pick so that they all nest. Line the picked boxes up from smallest to largest: the smallest has to fit inside the second smallest, the second smallest has to fit inside the third smallest, and this has to hold all the way to the last box.

Box bib_i fits inside box bjb_j if some rotation of bib_i makes each of its three side lengths shorter than the corresponding side of bjb_j. A box can be rotated any way you like.

Input

The input holds several sets of boxes, and the number of sets is not given in advance. The first line of each set has the number of boxes nn (0n5000 \le n \le 500). The next nn lines each give the length, width and height of one box. All three values are positive integers no greater than 1000, and each of the first two numbers is followed by a space, a lowercase x, and a space, so one line looks like length x width x height.

Input ends when nn is -1.

Output

For each set of boxes, print on its own line the size of the largest subset that nests completely. A set with no boxes has answer 0.