Classy#8183

Classy

1 second
128 megabytes
Easy

In his memoirs, comedian John Cleese humorously describes the differences between social classes by comparing his parents’ backgrounds: his father belonged to the class “middle-middle-middle-lower-middle”, while his mother belonged to the class “upper-upper-lower-middle”. Such subtle distinctions can often be confusing, so you are asked to write a program that sorts people by their social class in order to clearly demonstrate these differences.

There are three main levels: (highest), (middle), and (lowest). Clearly, the class is higher than , and is higher than . However, within each level there may be further distinctions. For example, the class upper\text{-}upper is higher than middle\text{-}upper, which in turn is higher than lower\text{-}upper. Moreover, any class ending with is higher than any class ending with .

Similarly, more complex class descriptions may contain additional levels, for example lower\text{-}middle\text{-}upper\text{-}middle\text{-}upper. When comparing classes of different lengths, the missing levels should be considered as . Thus, the classes and middle\text{-}upper are equivalent, as are middle\text{-}middle\text{-}lower\text{-}middle and lower\text{-}middle.

Input

The first line contains an integer n~(1 \le n \le 1000) — the number of people.

Each of the following lines contains a person's name (a non-empty string of lowercase Latin letters), followed by a colon, a space, and a class description. The class description consists of one or more modifiers followed by the word class. All parts are separated by single spaces. Each modifier is one of upper, middle, or lower. It is guaranteed that the input is valid and that all names are distinct. Each line contains at most characters.

Output

Print names, one per line, in order from the highest class to the lowest. If multiple people belong to the same class, output their names in lexicographical order.

Examples

Example 1

Loading
Loading