Alice Margatroid (アリス·マーガトロイド) can control puppets. What's more, she can control her pupet to control other pupets.
The puppets she controls directly
called the first-level puppet. And the puppets which are controlled by the first-level puppets are called the second-level puppet. So as the third, fourth and the ith-level.
Now your task is to tell me each puppet is what level.
This problem contains several cases.
The first line of each case is an integer N (0 ＜ N ≤ 1000), indicates the number of puppets.
Then N lines follows. Each line has two strings, the name of the ith puppet and the controller's name. You can imagine if the controller is Alice, then the puppet is the first-level puppet.
Every controller's name will be all appeared as a puppet's name before except Alice. Each name is no longer then 20.
For each case, you should output every puppet's names and levels, and order by level. If two puppets have the same level, then order by lexicographic.