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 n 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 bi fits inside box bj if some rotation of bi makes each of its three side lengths shorter than the corresponding side of bj. A box can be rotated any way you like.
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 n (0≤n≤500). The next n 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 n is -1.
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.