It is year 5000 A.D. Against all odds, mankind has survived, multiplied, and spread across the Solar System. New faiths, cults and alike coexist with religions that were considered traditional thousands of years ago. Among them, the cult to Masao, the legendary hero of the 21st century. (For his believers, now it is year 3017 A.M.) The problem is, the cult to Masao has so many factions and subfactions, that it is difficult to keep track of which was originated from which.
Consider the following example, which is just a tiny simplification, with two main trees of the cult to Masao:
$$\pstree[levelsep=40pt,treesep=20pt,arrows=->]{\Toval{\mbox{\normalsize Masaoism}}}{ \Toval{\mbox{\normalsize Masochism}} \Toval{\mbox{\normalsize Garrulism}} } \hspace{2cm} \pstree[levelsep=40pt,treesep=20pt,arrows=->]{\Toval{\mbox{\normalsize Longlongism}}}{ \Toval{\mbox{\normalsize Charism}} \pstree{\Toval{\mbox{\normalsize Longism}}} { \Toval{\mbox{\normalsize Intism}} } }$$
Among other relations, we can see that Garrulism was directly originated from Masaoism, Intism was originated from Longlongism after two steps, Charism and Longism belong to different branches of the same tree, and Masochism and Intism belong to different trees.
Please write a program that, given the origin of the factions of the cult to Masao, computes the relation among several pairs of factions.
Input consists of several cases. Every case begins with a number , followed by pairs of names and , which indicate that was directly originated from . Next comes the number of queries of the case , followed by pairs of names and , with . Assume , that is similar to for the large private test cases, that the relations correctly define one or more trees, and that no tree has more than levels.
For every query pair, print the relation between and . Suppose that a name not present in the description of the factions is an isolated tree by itself. Print a line with 10 dashes after the output for every case.
Input
5 Longism Intism Masaoism Garrulism Longlongism Charism Masaoism Masochism Longlongism Longism 4 Masaoism Garrulism Intism Longlongism Charism Longism Masochism Intism 0 1 z y
Output
Masaoism is 1 level(s) above Garrulism Longlongism is 2 level(s) above Intism Charism and Longism : same tree, different branches Masochism and Intism : different trees ---------- z and y : different trees ----------