Every year on July 1st, the residents of Quebec experience Moving Day. Most apartment leases begin and end on this day, so it is a popular time to move. The streets fill with moving trucks and anxious tenants packing and unpacking their belongings, waiting for a truck to become free or for a previous tenant to vacate an apartment. It is a busy but profitable time for moving companies.
You will write a program to help the residents of a small town plan the order in which they should move. Only one truck is available, so everyone who is moving must share it. Therefore the people must move one at a time. A person cannot move into a new house until the former tenant has moved out. Each person moves directly from their old house to their new house; a person may not move temporarily into another vacant house while waiting for their new house to be vacated.
You may assume that no two people are moving into the same house. You may assume that no two people are moving out of the same house. You may also assume that every house someone is moving into is either already vacant or is being vacated on Moving Day.
The first line contains the number $n$ ($1 \le n \le 100$) of people who are moving. Each of the following $n$ lines contains a person's name, followed by the address they are moving from and the address they are moving to. Because the town has only one street (Main St.), each address is a single integer between $1$ and $100$ inclusive. No name is longer than 100 characters, and names contain only alphanumeric characters.
Print the names of the people, one per line, in the order in which they should move. If several valid orders exist, print the lexicographically smallest one: compare the sequences of names using standard string ordering and print the smallest such sequence. Equivalently, at each step move the person with the smallest name among those who can move right now. If there is no order that guarantees each person's new house is vacant by the time they move into it, print only the word "Impossible".